Reputation: 637
Is there a way to declare something like
type do = ('a -> 'b)
in OCaml? Specifically, to declare a function signature as a type
Upvotes: 0
Views: 303
Reputation: 66808
For free types 'a
and 'b
,'a -> 'b
is not the type of any well behaved OCaml function, because it requires the function to produce a value of an arbitrary type.
So, you can't give a name to a type with unbound parameters:
# type uabfun = 'a -> 'b
Error: Unbound type parameter 'a
If you use specific types, there's no problem giving it a name:
# type iifun = int -> int;;
type iifun = int -> int
If type types 'a
and 'b
are parameters (rather than being free), there is also no problem:
# type ('a, 'b) abfun = 'a -> 'b;;
type ('a, 'b) abfun = 'a -> 'b
Upvotes: 2