Browse thread
Unbound type constructor
-
Stephan Tolksdorf
- Brian Rogoff
- Jacques Garrigue
- John Max Skaller
[
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: | Brian Rogoff <bpr@b...> |
| Subject: | Re: Unbound type constructor |
On Sat, 3 Feb 2001, Stephan Tolksdorf wrote: > I'm learning OCaml... > > The following code snippet fails due to an "unbound type constructor" > error. How could I achieve the intended result in OCaml? > > type combination = T1 of int | T2 of test | T3 of test * test > > class test = > object > method virtual get : combination > end The problem is that cuurrently you can't have classes and types in a mutually recursive declaration, and you can't even have "class types" in such declarations, but you can put "object types" (see the OCaml manual under Type Expressions) in and then use object types to constrain the return value of method get. # type combination = T1 of int | T2 of test | T3 of test * test and test = <get : combination>;; type combination = T1 of int | T2 of test | T3 of test * test type test = < get : combination > # class my_test = object(self) method get = T2 (self:>test) end;; class my_test : object method get : combination end There are probably other ways to do what you want too. -- Brian