From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id PAA06714; Sun, 10 Nov 2002 15:26:21 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id PAA06598 for caml-list@pauillac.inria.fr; Sun, 10 Nov 2002 15:26:20 +0100 (MET) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id OAA06532 for ; Sun, 10 Nov 2002 14:55:19 +0100 (MET) Received: from mallaury.noc.nerim.net (mallaury.noc.nerim.net [62.4.17.82]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id gAADtI507652 for ; Sun, 10 Nov 2002 14:55:18 +0100 (MET) Received: from localhost (noury.net1.nerim.net [62.212.98.223]) by mallaury.noc.nerim.net (Postfix) with ESMTP id 631A562D05 for ; Sun, 10 Nov 2002 14:55:15 +0100 (CET) Date: Sun, 10 Nov 2002 14:55:17 +0100 Mime-Version: 1.0 (Apple Message framework v482) Content-Type: text/plain; charset=US-ASCII; format=flowed Subject: [Caml-list] Camlp4 and lightweight records From: Nicolas Oury To: caml-list@inria.fr Content-Transfer-Encoding: 7bit Message-Id: <0B92F5B1-F4B4-11D6-8171-000393B2C8EA@ens-lyon.fr> X-Mailer: Apple Mail (2.482) Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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