From: skaller <skaller@users.sourceforge.net>
To: Erik de Castro Lopo <ocaml-erikd@mega-nerd.com>
Cc: caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Infix operators
Date: 15 Aug 2004 03:10:40 +1000 [thread overview]
Message-ID: <1092503440.29139.660.camel@pelican.wigram> (raw)
In-Reply-To: <20040814225919.0bed9f65.ocaml-erikd@mega-nerd.com>
On Sat, 2004-08-14 at 22:59, 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 ;;
There reason, roughly, is that it is very hard to combine
type inference with overloading. It can be done (there's
a paper on Citeseer describing an algorithm). It isn't
clear what the error message quality would be though.
The GCaml solution Richard Jones mentions:
# generic plus =
| int -> int -> int => (+)
| float -> float -> float => (+.)
;;
When you use this:
plus 1 1
plus 1.0 1.0
there is only a *single* plus function,
with several explicitly given typings --
thus avoiding the problem of combining
inference with overloading neatly.
--
John Skaller, mailto:skaller@users.sf.net
voice: 061-2-9660-0850,
snail: PO BOX 401 Glebe NSW 2037 Australia
Checkout the Felix programming language http://felix.sf.net
-------------------
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
next prev parent reply other threads:[~2004-08-14 17:10 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-08-14 12:59 Erik de Castro Lopo
2004-08-14 13:57 ` Richard Jones
2004-08-14 17:10 ` skaller [this message]
2004-08-14 19:04 ` [Caml-list] " Julian Brown
2004-08-14 19:52 ` [Caml-list] " 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=1092503440.29139.660.camel@pelican.wigram \
--to=skaller@users.sourceforge.net \
--cc=caml-list@inria.fr \
--cc=ocaml-erikd@mega-nerd.com \
/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