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: | Jun.Furuse@i... |
| Subject: | Re: easy print and read (was: [Caml-list] Why are arithmetic functions not polymorph?) |
Hello, > 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. Yes, in this case, it is easy to tell that there is only one applicable typing for plus one two, that is plus : float -> float -> float. But in general, nubmer of type case combinations may increase quite easily and searching applicable typing from them becomes quite inefficient. Moreover, when we have recursive generic values, the search space may be infinite! Therefore, we must restrict the search space of type case combinations in some manner (otherwise, typing may never terminates). The restriciton in the G'Caml implementation is quite simple, therefore you may feel some inconvenience: the type of plus one two is not inferred automatically, for example. -- Jun ------------------- 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