caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Julian Brown <brown@cs.bris.ac.uk>
To: caml-list@inria.fr
Subject: [Caml-list] Re: Infix operators
Date: Sat, 14 Aug 2004 19:04:09 +0000 (UTC)	[thread overview]
Message-ID: <slrnchsodl.1sp.brown@panic.cs.bris.ac.uk> (raw)
In-Reply-To: <20040814225919.0bed9f65.ocaml-erikd@mega-nerd.com>

On 2004-08-14, Erik de Castro Lopo <ocaml-erikd@mega-nerd.com> wrote:
> Hi all,
>
> I've got a number of defined types for which I'd like to define
> infix operators for addition, subtraction, multiplication etc.
>
> Unfortunately since each type needs is own infix operator I'm
> running out of ideas unique operator versions for each type.

I came up with a totally rubbish solution to this: define an "infix-ising"
operator like so which lets you use "long" operator names made of plain
characters:

  let (%) a b = b a

  let add a b = a + b
  let addf a b = a +. b

  5 %add 6
  10. %addf 12.

This is not a serious suggestion though, since it totally breaks under
lots of situations, mostly involving precedence. Still, I suppose there
might be a use for it somewhere.

Julian

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


  parent reply	other threads:[~2004-08-14 19:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-08-14 12:59 [Caml-list] " Erik de Castro Lopo
2004-08-14 13:57 ` Richard Jones
2004-08-14 17:10 ` skaller
2004-08-14 19:04 ` Julian Brown [this message]
2004-08-14 19:52   ` Jean-Baptiste Rouquier

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=slrnchsodl.1sp.brown@panic.cs.bris.ac.uk \
    --to=brown@cs.bris.ac.uk \
    --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).