-
Notifications
You must be signed in to change notification settings - Fork 4
Open
Description
(* an example with type variables that produces a bug *)
let map (x: 'a * 'a) (f:'a -> 'b) : ('b * 'b) =
let x1, x2 = x in
(f x1, x2)gives
val map : 'b * 'b -> ('b -> 'b) -> 'b * 'b = <fun>
whereas it should be (f x1, f x2)
keeping type abstracts prevents unification, which would have had the compiler yell at us:
let map (type a b) (x: a * a) (f:a -> b) : (b * b) =
let x1, x2 = x in
(f x1, x2)
gives us: Error: This expression has type a but an expression was expected of type b
Also, it's useful for GADTs (see GADT section)
Metadata
Metadata
Assignees
Labels
No labels