caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Richard Jones <rich@annexia.org>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Associativity precedence for the user-defined operator.
Date: Fri, 23 Jul 2004 15:36:51 +0100	[thread overview]
Message-ID: <20040723143651.GA12453@redhat.com> (raw)
In-Reply-To: <Pine.LNX.4.44.0407231614060.12107-100000@strudel.di.unipi.it>

On Fri, Jul 23, 2004 at 04:27:06PM +0200, Claudio Trento wrote:
> 
> Hi,
> 
> I've defined a set of new operetors, for instance:
> 
> let ( /+/ ) = add_num   (where add_num is a function that added two sometype 
> 			elements.) 
> 
> but I don't know if I can set associativity precedence for this operator,
> writing: el1 ( /+/ ) el2 ( /+/ ) el3 without parenthesis, what happens?

The easiest way to control associativity and precedence seems to be to
write a Camlp4 extension.  For example here is a Camlp4 extension I
wrote to create some left-associative ('LEFTA') ops:

open Pcaml

EXTEND
   expr: AFTER "apply"
   [ LEFTA
       [ e1 = expr; "map_with"; e2 = expr ->
           <:expr< List.map $e2$ $e1$ >>
       | e1 = expr; "iter_with"; e2 = expr ->
           <:expr< List.iter $e2$ $e1$ >>
       | e1 = expr; "filter_with"; e2 = expr ->
           <:expr< List.filter $e2$ $e1$ >>
       | e1 = expr; "concat_with"; e2 = expr ->
           <:expr< List.concat (List.map $e2$ $e1$) >>
       | e1 = expr; "apply_with"; e2 = expr ->
           <:expr< $e2$ $e1$ >>
       ]
   ];
END

Rich.

-- 
Richard Jones. http://www.annexia.org/ http://www.j-london.com/
Merjis Ltd. http://www.merjis.com/ - improving website return on investment
MAKE+ is a sane replacement for GNU autoconf/automake. One script compiles,
RPMs, pkgs etc. Linux, BSD, Solaris. http://www.annexia.org/freeware/makeplus/

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


  reply	other threads:[~2004-07-23 14:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-07-23 14:27 Claudio Trento
2004-07-23 14:36 ` Richard Jones [this message]
2004-07-23 17:42 ` Jean-Baptiste Rouquier
2004-07-23 19:52   ` John Prevost

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=20040723143651.GA12453@redhat.com \
    --to=rich@annexia.org \
    --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).