On Tue, 27 Sep 2011, Christophe Papazian wrote:
Please remember how types can be subtypes of other types :
consider
val f : int -> int
val g : int -> 'a
val h : 'a -> int
val i : 'a -> 'b
then the most general type is the type of g
and most specific type is type of h. In fact we have a diamond relation
between types :
h<f<g
h<i<g
and i and f are not related.
Why ?
because if you need a function of type like f (int -> int)
you can give h (if h can eat anything, it can eat int), but not g
(i don't now how to handle 'a if I only need a int).
So int is a subtype of 'a,
but int -> int is not a subtype of 'a -> 'b,
and 'a -> 'a is a valid subtype of int-> int.
uhm, I have a couple of questions I don't understand on your
explanation:
- why the most general type is int->'a and not 'a -> 'b?
- does this mean that I can't have a general type that could be matched
by 'a -> 'a list -> 'a list and int -> int -> int ?
Walter
--
--
Caml-list mailing list. Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs