From: Pierre Weis <pierre.weis@inria.fr>
To: malekith@pld-linux.org (Michal Moskal)
Cc: warplayer@free.fr, caml-list@inria.fr
Subject: Re: [Caml-list] Understanding why Ocaml doesn't support operator overloading.
Date: Sat, 30 Nov 2002 22:36:52 +0100 (MET) [thread overview]
Message-ID: <200211302136.WAA29169@pauillac.inria.fr> (raw)
In-Reply-To: <20021129172616.GC16911@roke.freak> from Michal Moskal at "Nov 29, 102 06:26:16 pm"
> On Fri, Nov 29, 2002 at 04:52:03PM -0000, Nicolas Cannasse wrote:
> > Of course the ML type system relies on type inference and need do choose the
> > "best available" type but what if we enrich the type system with an "OR"
> > operator ? Then if (+) is overloaded on floats, you'll get :
> >
> > f : int -> int OR float -> float
> > or something like a type constraint : f : 'a -> 'a where 'a in [int;float]
> >
> > This approach seems trivial to me, but I really can understand that this
> > require a lot of addins in the typing algorithms & theory. BTW, does one of
> > the upper approach has already been discussed ? any paper on it ? any
> > countersample that will make me feel stupid ? :)
>
> The problem is what *assembly code* should be generated for function f?
> Code to add 2 integers or code to add 2 floats? Hmm.. we'll have a
> problem then. Or maybe both? And choose versions of f based on type it
> is applied to? But then consider:
>
> let f x1 x2 ... xn = ((x1 + x1), (x2 + x2), ..., (xn + xn))
>
> you need to generate 2^n versions of f. We're getting to ugly things
> like C++ templates here.
>
> There is third answer: generate code that checks if it's passed int or
> float. But this has very significant perfomance impact.
>
> --
> : Michal Moskal ::::: malekith/at/pld-linux.org : GCS {C,UL}++++$ a? !tv
> : PLD Linux ::::::: Wroclaw University, CS Dept : {E-,w}-- {b++,e}>+++ h
> -------------------
There a fourth answer, more efficient than those approches, that we
call generic flows. See Jun's thesis for more detailed explanation...
Hope this helps,
Pierre Weis
INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://pauillac.inria.fr/~weis/
-------------------
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:[~2002-11-30 21:37 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-11-28 21:02 Jørgen Hermanrud Fjeld
2002-11-28 21:27 ` Jørgen Hermanrud Fjeld
2002-11-29 15:26 ` Xavier Leroy
2002-11-29 15:42 ` Christophe Raffalli
2002-11-29 16:52 ` Nicolas Cannasse
2002-11-29 17:26 ` Michal Moskal
2002-11-30 0:00 ` Mike Lin
2002-11-30 10:24 ` Michal Moskal
2002-11-30 23:06 ` Mike Lin
2002-11-30 21:41 ` William Lovas
2002-12-01 17:30 ` Pierre Weis
2002-12-01 23:41 ` William Lovas
2002-12-02 9:52 ` Remi VANICAT
2002-11-30 21:47 ` Pierre Weis
2002-12-01 7:40 ` Christophe Raffalli
2002-11-30 21:36 ` Pierre Weis [this message]
2002-11-30 21:33 ` Pierre Weis
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=200211302136.WAA29169@pauillac.inria.fr \
--to=pierre.weis@inria.fr \
--cc=caml-list@inria.fr \
--cc=malekith@pld-linux.org \
--cc=warplayer@free.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