Browse thread
[Caml-list] record declaration, SML
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2003-01-09 (18:28) |
From: | brogoff@s... |
Subject: | Re: [Caml-list] record declaration, SML |
Hi, You've noticed that OCaml records aren't like SML records. Here are a few places where they differ. You can't have anonymous records in OCaml, so in the case of a datatype declaration like yours you need something like type t = C of t_record and t_record = { f : int } If you hide the record definition, then you can't match on it, but I imagine you know that already. In the case of anonymous records as function arguments, you could try labels. 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. This is one of those annoyances of Caml (like the lack of overloading :) that you just need to get used to. SML is a bit better here IMO, but still not ideal; I think that there was an SML variant (SML#) that was appealing but it looks like that idea isn't going anywhere. There are a few other conveniences in SML record handling too, like the ... notation, that don't exist in OCaml. Oh yeah, also be careful initializing records with stateful functions, because you may be surprised at the order of evaluation. -- Brian On Thu, 9 Jan 2003, A. Ozmen wrote: > Hi, > > What's best translation of the following SML type? > datatype t = C of { f : int } > > I have to define extra record types, I guess. Then, not including these > types in interface (.mli) files? Is this the right approach? > > Thanks. > __________________________________________________________ > Get your Private, Free Email from HTTP://www.DmailMan.Com > ------------------- > 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 > ------------------- 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