Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Why are arithmetic functions not polymorph?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-06-07 (14:48)
From: Jun.Furuse@i...
Subject: Re: easy print and read (was: [Caml-list] Why are arithmetic functions not polymorph?)

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

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: