Reputation: 4177
I'm reading this OCaml file and it contains the following:
type z = Z of z
This looks like z is infinitely recursive. How is it useful and how can I even construct such a type?
Upvotes: 2
Views: 162
Reputation: 66818
I don't think this type is particularly useful, except possibly as a test case in type theory.
You can construct values of the type like this:
# let rec x = Z x;;
val x : z = Z <cycle>
# let rec q = Z (Z q);;
val q : z = Z (Z <cycle>)
Once you have a value of the type you can readily construct other values of course:
# let y = Z (Z x);;
val y : z = Z (Z (Z <cycle>))
Upvotes: 6