This is more for personal curiosity, but maybe someone can point me in the right direction. If I have the following piece of code
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:
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