Is it possible to explicitly write down a type that's non-polymorphic but has delayed unification like underscore types?
So, OCaml will sometimes produce a type that the top-level prints with a leading underscore (e.g. _a
) in the course of type checking. Specifically, these appear when instantiating an empty Hashtbl.t
and under some other circumstances.
# Hashtbl.create 1;;
- : ('_a, '_b) Hashtbl.t = <abstr>
However, these types cannot be explicitly referred by the user in source code.
# (5: int);;
- : int = 5
# (5: 'a);;
- : int = 5
# (5: '_a);;
Error: The type variable name '_a is not allowed in programs
You can create an explicitly non-polymorphic function by exploiting the lack of higher-rank polymorphism in OCaml
# let id = snd ((), fun y -> y);;
val id : '_a -> '_a = <fun>
# (fun () -> fun y -> y) ();;
- : '_a -> '_a = <fun>
I'd like to be able to do something like
let id : <some magical type> = fun x -> x
and not rely on a limitation of the type system that could conceivably go away in the future.
.mli
files. In retrospect, this wasn't a great approach. – Gregory Nisbet