caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Markus Mottl <markus.mottl@gmail.com>
To: OCaml <caml-list@inria.fr>
Subject: Camlp4: extending syntax of record definitions
Date: Mon, 18 Apr 2005 15:07:06 -0400	[thread overview]
Message-ID: <f8560b805041812072f446158@mail.gmail.com> (raw)

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 = lower <= x && x <= upper
  let int_positive x = x >= 0

  type some_record =
    {
      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 =
    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


             reply	other threads:[~2005-04-18 19:07 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-18 19:07 Markus Mottl [this message]
2005-04-18 20:19 ` [Caml-list] " Martin Jambon
2005-04-19  7:25   ` too few public grammar entry points Stefano Zacchiroli
2005-04-19 15:16     ` [Caml-list] " Markus Mottl
2005-04-19 15:13   ` [Caml-list] Camlp4: extending syntax of record definitions Markus Mottl
2005-04-19 21:51     ` Martin Jambon

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=f8560b805041812072f446158@mail.gmail.com \
    --to=markus.mottl@gmail.com \
    --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).