caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Merijn de Jonge" <merijn.de.jonge@gmail.com>
To: caml-list@yquem.inria.fr
Subject: Writing Identity Functors (or Wrapper modules) in OCAML
Date: Mon, 27 Feb 2006 15:49:51 +0100	[thread overview]
Message-ID: <f40e02a60602270649w5959ac06ldf2bf1f9820bbb72@mail.gmail.com> (raw)

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

             reply	other threads:[~2006-02-27 14:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-27 14:49 Merijn de Jonge [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f40e02a60602270649w5959ac06ldf2bf1f9820bbb72@mail.gmail.com \
    --to=merijn.de.jonge@gmail.com \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).