caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] still silly issues on polymorphic types
@ 2011-09-27 11:46 Walter Cazzola
  2011-09-27 12:57 ` Christophe Papazian
  2011-09-27 13:16 ` Jacques Garrigue
  0 siblings, 2 replies; 12+ messages in thread
From: Walter Cazzola @ 2011-09-27 11:46 UTC (permalink / raw)
  To: OCaML Mailing List

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1350 bytes --]

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

--

[-- Attachment #2: Type: TEXT/PLAIN, Size: 75 bytes --]

module Sum = struct
  let op = fun x y -> x+y ;;
  let init = 0 ;;
end

[-- Attachment #3: Type: TEXT/PLAIN, Size: 82 bytes --]

module type OpVarADT = 
 sig
   val op: 'a -> 'b -> 'c
   val init : 'c
 end

[-- Attachment #4: Type: TEXT/PLAIN, Size: 182 bytes --]

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

[-- Attachment #5: Type: TEXT/PLAIN, Size: 89 bytes --]

module StringConcat = struct
  let op = fun x y -> y @ [x] ;;
  let init = [] ;;
end

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2011-09-29 10:50 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-27 11:46 [Caml-list] still silly issues on polymorphic types Walter Cazzola
2011-09-27 12:57 ` Christophe Papazian
2011-09-27 13:49   ` Walter Cazzola
2011-09-27 15:26     ` Christophe Papazian
2011-09-27 18:43       ` Walter Cazzola
2011-09-27 19:25         ` Thibault Suzanne
2011-09-27 13:16 ` Jacques Garrigue
2011-09-27 13:58   ` Walter Cazzola
2011-09-27 19:45     ` Pierre Chopin
2011-09-27 20:22       ` Walter Cazzola
2011-09-27 23:58         ` Jacques Garrigue
     [not found]         ` <266E7048-C3BB-4B9E-9760-9D52993A1C86@math.nagoya-u.ac.jp>
2011-09-29 10:27           ` Walter Cazzola

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).