Version française
Home     About     Download     Resources     Contact us    
Browse thread
Type issue
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Florian Weimer <fw@d...>
Subject: Re: [Caml-list] Type issue
* Jonathan T. Bryant:

> # 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>

# let rec g t = match t with
      Cond (c,t,e) -> if f c then g t else g e
    | Value x -> x
  ;;
    val g : 'a t -> 'a = <fun>

The return value of f can't be generalized 'a because it's constrained
to bool in the if expression.  This problem does not arise for g.