In Haskell you can do the following:
Prelude> data Foo = Foo Bar; data Bar = Bar Foo
How can you do the same thing in OCaml? I tried:
___
# type foo = Foo of bar;; type bar = Bar of foo;;
Error: Unbound type constructor bar
Is it even possible to define mutually recursive data types in OCaml? If not then why?
Comparing data definitions to let expressions: mutually recursive data types correspond to using let rec
(or more appropriately type rec
for want of a better phrase). What are the advantages of being able to define mutually recursive data types? My foobar example is trivial. Can you think of any non-trivial uses of mutually recursive data types?
type 'a t = Stream of (unit -> ('a * 'a t) option)
– Earthward