From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 8FC57BC48 for ; Mon, 18 Apr 2005 21:07:08 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j3IJ7850006804 for ; Mon, 18 Apr 2005 21:07:08 +0200 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id VAA19772 for ; Mon, 18 Apr 2005 21:07:07 +0200 (MET DST) Received: from wproxy.gmail.com (wproxy.gmail.com [64.233.184.199]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j3IJ77Ee002904 for ; Mon, 18 Apr 2005 21:07:07 +0200 Received: by wproxy.gmail.com with SMTP id 69so1276091wra for ; Mon, 18 Apr 2005 12:07:06 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:mime-version:content-type:content-transfer-encoding:content-disposition; b=s0G+9TnZQHAM799gJxj17AD6XvqsoTzPi20bawgVOX5Q3hfVV1aXxaz0pOMrfiFKhqF9HRZYPOlwWXN/CwnW5+d0FudfgeW1cM1ksn5t8iDIPJ/tDcYX3TPIV9lKlHDYTJGksuwzPUoU1+nBt2vatMhKu6pngOanQ3nmuqH+/Nk= Received: by 10.54.32.51 with SMTP id f51mr2558818wrf; Mon, 18 Apr 2005 12:07:06 -0700 (PDT) Received: by 10.54.22.11 with HTTP; Mon, 18 Apr 2005 12:07:06 -0700 (PDT) Message-ID: Date: Mon, 18 Apr 2005 15:07:06 -0400 From: Markus Mottl Reply-To: Markus Mottl To: OCaml Subject: Camlp4: extending syntax of record definitions Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline X-Miltered: at concorde with ID 4264055C.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 4264055B.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; markus:01 mottl:01 markus:01 mottl:01 syntax:01 annotations:01 foo:01 foo:01 grammar:01 grammars:01 ocaml:01 1.0:98 1.0:98 assert:01 functions:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.5 required=5.0 tests=INFO_TLD,RCVD_BY_IP autolearn=disabled version=3.0.2 X-Spam-Level: Hi, I'd like to add annotations to record definitions that allow the automatic generation of validation functions. Here is a simplified example: let float_range lower upper x =3D lower <=3D x && x <=3D upper let int_positive x =3D x >=3D 0 type some_record =3D { foo : float validate float_range 1.0 2.0; bar : int validate int_positive; } The "validate" keyword would essentially allow attaching a function to each record field, which is called to assert some properties. E.g. the following function would be automatically generated from the above type definition: let validate__some_record r =3D float_range 1.0 2.0 r.foo && int_positive r.bar Not being a camlp4-expert my problem is that I'm not sure how to go about extending the grammar. What would be the most convenient starting point? Extending existing grammars, starting one from scratch, etc.? Some rough outline on what to do would be nice. Thanks in advance! Best regards, Markus -- Markus Mottl http://www.ocaml.info markus.mottl@gmail.com