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] Camlp4 and lightweight records
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2002-11-10 (14:26)
From: Nicolas Oury <Nicolas.Oury@e...>
Subject: [Caml-list] Camlp4 and lightweight records
I don't know if it is the place for that, nor it will interest someone 
but I've made up a small (80 lines) extension with camlp4 that allows 
one to use lightweight records in Ocaml.

That are records that type haven't to be declared before use - like in 
SML but without the typing retriction.

For example :

let test = {| a = 5; b = "hello"; c = true ; i = "world" |};;

is a valid statement.
Labels can be used any times and with different types.

One can

* retrieve the value of a field  :

  #    ##c test

----> true

* change -- functionally --  the value of fields
   let test 2 = test with {| c = false ; i = "earth" |}

* take a part of a record
let test3 = take b, i in test

* There are SML like tuples :
let tuple = {< 5 ; true ; 9 ; "hi" >}
is equivalent to a record with fields_name field_1,... field_4. Each 
field can be accessed with :
For example :
@2 tuple returns    true

@i is polymorhpic in the size of the tuple.

Internally records are implemented as :
let module  A = class a
definition of the field
in new A.a, which allows a correct typing of the records and tuples.

If someone found this interesting, it can be downloaded at:

(small download ~1Kb )

Best regards,
Nicolas Oury
To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: