On Tue, 27 Sep 2011, Jacques Garrigue wrote:

On 2011/09/27, at 20:46, Walter Cazzola wrote:

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

It seems that your continuation functor has not the right specification.
Namely, there is no way you can provide a meaningful function of
type 'a -> 'b -> 'c (i.e. a -> b -> c for all possible a, b, and c)
other than raising an exception or going into an infinite loop.
I think that you meant something else, like

type a and b and c
val op : a -> b -> c

which would let you give a specific function for op.

uhm, I've tried to follow your advice but the problem persists (attached
the new version) when I try to apply the functor I get the following
error:

# module M1 = Continuation(Sum) ;;
Error: Signature mismatch:
       Modules do not match:
         sig
           type a = int
           and b = int
           and c = int
           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

But probably I misinterpreted your advice.

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

module Continuation (OP : OpVarADT.OpVarADT) = 
  struct
    let arg x = fun y continuation -> continuation (OP.op x y) ;;
    let stop x = x;;
    let f g = g OP.init;;
  end
module type OpVarADT = 
 sig
   type a and b and c
   val op: a -> b -> c
   val init : 'c
 end
module Sum = struct
  type a=int and b=int and c=int
  let op = fun x y -> x+y ;;
  let init = 0 ;;
end

Reply via email to