Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Infix operators
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Julian Brown <brown@c...>
Subject: [Caml-list] Re: Infix operators
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