Version française
Home     About     Download     Resources     Contact us    
Browse thread
changing the type of records using "with"
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Eric Breck <ebreck@c...>
Subject: changing the type of records using "with"
Hi folks,

I noticed the following behavior of the typing system:

# type 'a foo = {a: 'a; b: int};;
type 'a foo = { a : 'a; b : int; }
# let one = { a = (); b = 5};;
val one : unit foo = {a = (); b = 5}
# let two = {one with a = "Hello"};;
val two : string foo = {a = "Hello"; b = 5}

i.e. "{one with ... }" can have a different polymorphic type argument  
than "one" does.  This has been handy for me on a couple of  
occasions, but is it a documented feature that I can count on working  
in future versions of ocaml, or is it a quirk of the current version?

thanks,

Eric Breck