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
[Caml-list] record declaration, SML
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-01-10 (09:21)
From: Xavier Leroy <xavier.leroy@i...>
Subject: Re: [Caml-list] record declaration, SML
> > What's best translation of the following SML type?
> > datatype t = C of { f : int }
> In the case of records in a module sharing field names, well, you can't do 
> that either, so you'll need to use classes or find some way to disambiguate 
> the fields.

Sometimes, it's acceptable to just omit the record type:

        type t = C of int

You lose the naming of the arguments of the constructor, but for small
numbers of arguments (e.g. 1 or 2), this is often tolerable.

> There are a few other conveniences in SML record handling too, like the ... 
> notation, that don't exist in OCaml. 

You mean, in pattern-matching over records?  Caml offers the same
functionality without the ... notation, e.g.

        type r = { x: int; y: int }

        match r with { x = 1 } -> ...

Because records are declared in advance, there is no requirement that
all record labels be mentioned in a pattern matching.

- Xavier Leroy
To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: