Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
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 caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners