caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Writing Identity Functors (or Wrapper modules) in OCAML
@ 2006-02-27 14:49 Merijn de Jonge
  2006-02-27 15:04 ` [Caml-list] " Julien Signoles
  2006-02-27 15:06 ` [Caml-list] Writing Identity Functors (or Wrapper modules) in OCAML Jean-Christophe Filliatre
  0 siblings, 2 replies; 5+ messages in thread
From: Merijn de Jonge @ 2006-02-27 14:49 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 1944 bytes --]

Hi,

I've problems in writing an Identity Functor in OCAML that I want to use as
a wrapper module.

Consider the following OCAML definition containing the type IHelloWorld, the
module World, an Identity functor
defined in the module Wrapper, and the binding of World to Wrapper in the
module TestWrapper:

      module type IHelloWorld =
      sig
         type helloWorldType = Hello | World
        val hello : unit -> helloWorldType
      end

      module Wrapper (X: IHelloWorld) : IHelloWorld =
      struct
        type helloWorldType = X.helloWorldType
        let hello = X.hello
      end

      module World : IHelloWorld =
      struct
         type helloWorldType = Hello | World
         let hello () = Hello
      end

      module TestWrapper = Wrapper(World)

If I compile this module I get the following output from the OCAML compiler

      mdejonge> ocamlc wrapper-demo.ml
      File "wrapper-demo.ml", line 8, characters 3-85:
      Signature mismatch:
      Modules do not match:
        sig
          type helloWorldType = X.helloWorldType
          val hello : unit -> X.helloWorldType
        end
      is not included in
        IHelloWorld
     Type declarations do not match:
        type helloWorldType = X.helloWorldType
      is not included in
        type helloWorldType = Hello | World

If I change helloWorldType into "int" and let the definition of hello yield
(say) 10:

      type helloWorldType = int
      let hello () = 10

Then the compiler issues no error at all!

Using a "with type" construct in the module definition of Wrapper does not
work:

      module Wrapper (X: IHelloWorld) : IHelloWorld  with type
helloWorldType = X.helloWorldType =

I don't understand what is going on. Can anyone help me understanding this
problem and help me
writing a wrapper module as above?

Many thanks in advance

Best regards,
Merijn de Jonge

[-- Attachment #2: Type: text/html, Size: 2906 bytes --]

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

end of thread, other threads:[~2006-02-27 15:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-27 14:49 Writing Identity Functors (or Wrapper modules) in OCAML Merijn de Jonge
2006-02-27 15:04 ` [Caml-list] " Julien Signoles
2006-02-27 15:13   ` [Caml-list] Writing Identity Functors (or Wrapper modules) inOCAML Sebastian Egner
2006-02-27 15:20     ` Merijn de Jonge
2006-02-27 15:06 ` [Caml-list] Writing Identity Functors (or Wrapper modules) in OCAML Jean-Christophe Filliatre

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