Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: "blue storm" <bluestorm.dylc@gmail.com>
To: caml-list@yquem.inria.fr
Subject: [camlp4 extension] pa_refutable : request for comments
Date: Tue, 25 Dec 2007 18:36:27 +0100	[thread overview]
Message-ID: <527cf6bc0712250936k7b7c713eg7ec4a34da4fd2f26@mail.gmail.com> (raw)

Hi,

I just created my first "serious" camlp4 (3.10) extension. I'm looking
for comments, and have some questions too.

The extension (to the classical syntax) enables an explicit use of
non-irrefutable pattern matching in "let" declarations :
let refutable hd::tl = ...
let refutable [a; b; c] = List.map foo ['a'; 'b'; 'c']
let rec refutable func (Some thing) = ...

The code is available here : http://bluestorm.info/tmp/pa_refutable.ml.html
(side question : are 80 lines of code short enough to be included in
my message ? what is the mailing-list recommended behaviour here ?)

The actual error-reporting is rather naive : the extension generate a
string containing the location of the refutable pattern in the
original source, wich is raised at runtime using "failwith".. Is there
a more elegant way to do that ?

There are 6 repetitive lines of code in my refutable_mono function :
    let binds_patt binds _loc =
      let patt_of_id (id, _loc) = <:patt< $lid:id$ >> in
      Ast.PaTup _loc (Ast.paCom_of_list (List.map patt_of_id binds)) in
    let binds_expr binds _loc =
      let expr_of_id (id, _loc) = <:expr< $lid:id$ >> in
      Ast.ExTup _loc (Ast.exCom_of_list (List.map expr_of_id binds)) in
Is there an better way to do this ?

Lastly, i had to duplicate work in the grammar-modification part,
because i didn't manage to use the "opt_rec" rule. I'm not aware of
the subtleties of camlp4 parsing; is there another way ?


             reply	other threads:[~2007-12-25 17:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-25 17:36 blue storm [this message]
2007-12-25 20:50 ` [Caml-list] " Nicolas Pouillard
2007-12-25 22:49   ` blue storm

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=527cf6bc0712250936k7b7c713eg7ec4a34da4fd2f26@mail.gmail.com \
    --to=bluestorm.dylc@gmail.com \
    --cc=caml-list@yquem.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