In OCaml, let f (x : 'a) : 'a list = x :: [0] has signature val f : int -> int list.
When I try to define a similar function in Standard ML, fun f (x : 'a) : 'a list = x :: [0], there is an error.
SML/NJ:
- fun f (x : 'a) : 'a list = x :: [0];
stdIn:2.6-2.14 Error: operator and operand do not agree [overload - user bound tyvar]
operator domain: 'a * 'a list
operand: 'a * 'Z[INT] list
in expression:
x :: 0 :: nil
Poly/ML:
> fun f (x : 'a) : 'a list = x :: [0];
poly: : error: Type error in function application.
Function: :: : 'a * 'a list -> 'a list
Argument: (x, [0]) : 'a * int list
Reason: Can't unify int to 'a (Cannot unify with explicit type variable)
Found near x :: [0]
Static Errors
What is the difference between the type system in OCaml and Standard ML that causes an error to appear for Standard ML but not for OCaml?