Browse thread
circular types?
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Pierre Weis <Pierre.Weis@i...> |
| Subject: | Re: circular types? |
> How do I do this:
>
> type foo = B of bar
> type bar = F of foo
>
> That is, I want two types to refer to each other.
It's exactly similar to value definitions: put a ``and'' between the
two recursive definitions.
type foo = B of bar
and bar = F of foo
Then you can define recursively a f of type foo and a b of type bar as in:
let rec f = B b
and b = F f;;
val f : foo =
B
(F
(B
(F
(B
(F
(B
(F ...
)))))))
val b : bar =
F
(B
(F
(B
(F
(B
(F
(B
(F ...
))))))))
Hope this helps,
Pierre Weis
INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://cristal.inria.fr/~weis/