Browse thread
[Caml-list] Why are arithmetic functions not polymorph?
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Stefano Zacchiroli <zack@b...> |
| Subject: | Re: easy print and read (was: [Caml-list] Why are arithmetic functions not polymorph?) |
On Fri, Jun 06, 2003 at 09:40:16AM -0700, brogoff@speakeasy.net wrote:
> BTW, someone (Brian Hurt?) brought up a nice simple example of where the
> current generic polymorphism seems a bit weak
>
> generic one = | int => 1 | float => 1.0 ;;
> generic two = | int => 2 | float => 2.0 ;;
> generic plus = | float -> float -> float => (+.) | int -> int -> int => (+);;
>
> plus one two;; (* Can't determine plus without at least one type annotation *)
>
> and it would be nice if in such situations the correct plus could be inferred.
I haven't tried GCaml, I've just read the README you pointed out and it
seems to address your issue:
How about "plus one one"? There are two possibilities: adding integer
1's or float 1.0's? In such ambiguous situation, the type inference
algorithm takes the first one defined as defaults: plus one one is
typed as (plus : int -> int -> int) (one : int) (one : int)
I don't think that "plus one two" is typed differently ...
Cheers.
--
Stefano Zacchiroli -- Master in Computer Science @ Uni. Bologna, Italy
zack@{cs.unibo.it,debian.org,bononia.it} - http://www.bononia.it/zack/
" I know you believe you understood what you think I said, but I am not
sure you realize that what you heard is not what I meant! " -- G.Romney
-------------------
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