Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Writing Identity Functors (or Wrapper modules) in OCAML
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2006-02-27 (14:49)
From: Merijn de Jonge <>
Subject: Writing Identity Functors (or Wrapper modules) in OCAML

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 =
         type helloWorldType = Hello | World
        val hello : unit -> helloWorldType

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

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

      module TestWrapper = Wrapper(World)

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

      mdejonge> ocamlc
      File "", line 8, characters 3-85:
      Signature mismatch:
      Modules do not match:
          type helloWorldType = X.helloWorldType
          val hello : unit -> X.helloWorldType
      is not included in
     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

      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