let f : H.t -> int =
match H.ty with
| Int -> (fun (a : H.t) -> (a : int))
| _ -> assert false
;;
Error: This expression has type H.t but an expression was expected of type
int
let f : H.t -> int = fun (a : H.t) ->
match H.ty with
| Int -> (a : int)
| _ -> assert false
;;
Error: This expression has type H.t but an expression was expected of type
int
let f : H.t -> int =
let aux : type a. a ty -> a -> int = function
| Int -> (fun a -> a)
| _ -> assert false
in
aux H.ty
;;
(* val f : H.t -> int = <fun> *)
I can't quite come up with a clear mental model of why in-lining the pattern matching in the first versions of [f]t would not type check. I tried adding some more type coercions without great success. I'd be very grateful to get some feed back about this restriction.
Thanks,
Mathieu