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: Richard Jones <rich@a...>
Subject: Re: [Caml-list] Infix operators
On Sat, Aug 14, 2004 at 10:59:19PM +1000, 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.
> 
> Why is it not possible to do something like:
> 
>     let ( ++ ) (a:float) (b:float) = a +. b ;;
> 
>     let ( ++ ) (a:int) (b:int) = a + b ;;
> 
> which with the full type specification should allow the compiler
> to figure out which version to use in a given situation.

GCaml can do this:

http://pauillac.inria.fr/~furuse/generics/

# generic plus =
  | int -> int -> int => (+)
  | float -> float -> float => (+.)
  ;;

(Actually, I'm not sure whether or not it can do the infix ops part).

What is the status of GCaml w.r.t it becoming a part of standard
OCaml?

Rich.

-- 
Richard Jones. http://www.annexia.org/ http://www.j-london.com/
Merjis Ltd. http://www.merjis.com/ - improving website return on investment
MOD_CAML lets you run type-safe Objective CAML programs inside the Apache
webserver. http://www.merjis.com/developers/mod_caml/

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