]>
Jonathan T Bryant wrote:
> List,
>
> I don't understand the following typing:
>
> # type 'a t = Cond of bool t * 'a t * 'a t | Value of 'a;;
> type 'a t = Cond of bool t * 'a t * 'a t | Value of 'a
>
> # let rec f t = match t with
> Cond (c,t,e) -> if f c then f t else f e
> | Value x -> x
> ;;
> val f : bool t -> bool = <fun>
The type system does not infer polymorphic recursion: the type of a
recursive function cannot be more general than any of its occurences
within its body.
You can get around this limitation in various ways. E.g., with recursive
modules:
module rec M : sig val f : 'a t -> 'a end =
struct
let rec f t = match t with
| Cond (c,t,e) -> if M.f c then f t else f e
| Value x -> x
end
let f = M.f
-- Alain