Version française
Home     About     Download     Resources     Contact us    
Browse thread
strange behavior with record type definition
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Christophe TROESTLER <debian00@t...>
Subject: Re: [Caml-list] strange behavior with record type definition
On Sat, 12 Nov 2005, Florent <florentflament@aist.enst.fr> wrote:
> 
> Ok but with these two record types defined :
>     type t0 = { x : int ; y : int } ;;
>     type t1 = { x : int } ;;
> 
> There is no ambiguity about the following expression's type:
>     { x = 0 ; y = 0 } ;;
> Why can't the t0 type be infered ?

As said by Nicolas, what would be the type of

let f r = { r with x = 1 }

> And with this function definition,
>     let get_y (t:t0) = t.x ;;
> I explicitly say to the compiler that t is of type t0, so why does the 
> compiler infer a t1 type when trying to get the x label of a t0 type value ?

Because (at this point) t.x implies t is of type t1.  If you do not
care to access the fields of t0 after, just reorder your definitions:

  type t0 = { x : int ; y : int }
  let get_y t = t.x
  type t1 = { x : int }

ChriS