caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Nicolas Oury <Nicolas.Oury@ens-lyon.fr>
To: caml-list@inria.fr
Subject: [Caml-list] Camlp4 and lightweight records
Date: Sun, 10 Nov 2002 14:55:17 +0100	[thread overview]
Message-ID: <0B92F5B1-F4B4-11D6-8171-000393B2C8EA@ens-lyon.fr> (raw)

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 :
@i.
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:

http://www.ens-lyon.fr/~noury/lw_records.tgz

(small download ~1Kb )

Best regards,
Nicolas Oury
-------------------
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


                 reply	other threads:[~2002-11-10 14:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0B92F5B1-F4B4-11D6-8171-000393B2C8EA@ens-lyon.fr \
    --to=nicolas.oury@ens-lyon.fr \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).