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.



Le 27 sept. 11 à 13:46, Walter Cazzola a écrit :

Dear all,
I'm still playing around with functors, modules and polymorphism but
I've some problems with this last concept.

In the attached files I have tried to implement a sort of function with a variable number of arguments (based on continuation) and to generalize
the approach I've used a functor (OpVarADT) where I defined the
operation of type 'a -> 'b -> 'c but seems that it is not general enough
to contain int->int->int or 'a -> 'a list -> 'a list

This is the functor instantiation with the errors I get:

 # module M0 = Continuation(StringConcat) ;;
 Error: Signature mismatch:
        Modules do not match:
          sig val op : 'a -> 'a list -> 'a list val init : 'a list end
        is not included in
          OpVarADT.OpVarADT
        Values do not match:
          val op : 'a -> 'a list -> 'a list
        is not included in
          val op : 'a -> 'b -> 'c
 # module M1 = Continuation(Sum) ;;
 Error: Signature mismatch:
        Modules do not match:
          sig val op : int -> int -> int val init : int end
        is not included in
          OpVarADT.OpVarADT
        Values do not match:
          val op : int -> int -> int
        is not included in
          val op : 'a -> 'b -> 'c

I'm sure I'm doing something wrong but I can't see what, any help is
welcome

TIA

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

<sum.ml><OpVarADT.mli><continuation.ml><concat.ml>



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

Reply via email to