caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Camlp4: extending syntax of record definitions
@ 2005-04-18 19:07 Markus Mottl
  2005-04-18 20:19 ` [Caml-list] " Martin Jambon
  0 siblings, 1 reply; 6+ messages in thread
From: Markus Mottl @ 2005-04-18 19:07 UTC (permalink / raw)
  To: OCaml

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2005-04-19 21:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-18 19:07 Camlp4: extending syntax of record definitions Markus Mottl
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

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).