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: | Jacques Garrigue <garrigue@k...> |
| Subject: | Re: Unbound type constructor |
> 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
Since you cannot have mutual recursion between a type definition and a
class definition, you have to use parameterization. In this case this
is very easy, but this can get heavier when you have lots of mutually
recursive types.
type 'a combination = T1 of int | T2 of 'a | T3 of 'a * 'a
class virtual test =
object
method virtual get : test combination
end
> PS: Naive question, why aren't there type members in OCaml classes?
Because classes are not modules...
The technical explanation is rather complex, but you can just think
about the fact class types are just object types, and the compiler
should be able to infer object types without type annotations. In
general you cannot infer type members.
Jacques Garrigue