Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
RE: Record typing question
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Don Syme <dsyme@m...>
Subject: RE: Record typing question

>Spooky, I raised this point a few days ago!

Ah ha - I see that now.  I haven't been keeping up to date with the
discussion list!

>    type 'a foo = { a: 'a; b: 'a }
>    let f x = { x with a = 1 }

> Here "f: 'a foo -> int foo" won't wash, because the "b" field will
> stay an int, contra the definition.  Before lifting the current
> restriction, one would have to check that no type equalities between
> fields are broken.

I guess it should be f: int foo -> int foo.  All the field assignments would
act in parallel as far as the type system goes, so

    type 'a foo = { a: 'a; b: 'a; c: int }
    let f x = { x with a = [x.a]; b = [x.b]  }

would be f: 'a foo -> 'a list foo