Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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: 2004-08-14 (19:04)
From: Julian Brown <brown@c...>
Subject: [Caml-list] Re: Infix operators
On 2004-08-14, Erik de Castro Lopo <> 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

  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.


To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: