Recursive Types in Ocaml
Why can I not have a type like this in OCaml?
type t = string * (Left of t | Right of t)
Is there a type-theoretic reason for it?
« Continuation Typing Questions | Main | Setting Up CVS »
Why can I not have a type like this in OCaml?
type t = string * (Left of t | Right of t)
Is there a type-theoretic reason for it?
Comments
You can do this in O'Caml using polymorphic variants, which allow you to define anonymous variant types:
a value of this type can be defined as:
Type theoretically, the type is just μX. String * (X + X), where μX. denotes a recursive type.
Posted by: Bob Atkey | October 11, 2005 6:17 PM
I see; the problem was in the necessity of a name for the sum type. Jeremy Yallop pointed out privately that this works as well:
Thanks, both.
Posted by: ezra | October 13, 2005 4:29 PM