# Generalisation error

**URL:** <https://discuss.ocaml.org/t/generalisation-error/14216>\
**Category:** Learning\
**Tags:** type-system\
**Created:** [February 29, 2024, 9:00am UTC](https://discuss.ocaml.org/t/generalisation-error/14216 "2024-02-29T09:00:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nhuber](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/nhuber/32/3939_2.png) [@nhuber](https://discuss.ocaml.org/u/nhuber)\
**Post date:** [February 29, 2024, 9:00am UTC](https://discuss.ocaml.org/t/generalisation-error/14216/1 "2024-02-29T09:00:31Z")

</div>

This is more for personal curiosity, but maybe someone can point me in the right direction. If I have the following piece of code

```auto
type 'a t = 'a list 
let f : _ t -> int t = List.map (fun _ -> 1) 
let f' (l : _ t) : int t = List.map (fun _ -> 1) l 

```

then the definition of function `f` causes an error:

```txt
2 | let f : _ t -> int t = List.map (fun _ -> 1)
Error: The type of this expression, '_weak1 t -> int t,
contains type variables that cannot be generalized

```

While I don’t fully understand why the type system cannot generalise the type variable here, that is actually not my main question. For all odds and purposes I thought that the two definitions `f` and `f'` are equivalent, however, the second one does not give an error.

Thanks for any input 🙂

---

<div class="post-metadata">

**Author:** ![vlaviron](https://avatars.discourse-cdn.com/v4/letter/v/ec9cab/32.png) [@vlaviron](https://discuss.ocaml.org/u/vlaviron)\
**Post date:** [February 29, 2024, 9:08am UTC](https://discuss.ocaml.org/t/generalisation-error/14216/2 "2024-02-29T09:08:40Z")

</div>

This is called the value restriction. More information is in the manual (See [this section](https://v2.ocaml.org/manual/polymorphism.html#ss:valuerestriction) for instance).  
The first definition (`f`) is not a value in the sense of lambda-calculus semantics, while the second (`f'`) is.

---

<div class="post-metadata">

**Author:** ![nhuber](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/nhuber/32/3939_2.png) [@nhuber](https://discuss.ocaml.org/u/nhuber)\
**Post date:** [February 29, 2024, 10:18am UTC](https://discuss.ocaml.org/t/generalisation-error/14216/3 "2024-02-29T10:18:06Z")

</div>

Thank you! That’s exactly what I was looking for 🙂
