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

* Re: [Caml-list] Writing Identity Functors (or Wrapper modules) in OCAML
  2006-02-27 14:49 Writing Identity Functors (or Wrapper modules) in OCAML Merijn de Jonge
@ 2006-02-27 15:04 ` Julien Signoles
  2006-02-27 15:13   ` [Caml-list] Writing Identity Functors (or Wrapper modules) inOCAML Sebastian Egner
  2006-02-27 15:06 ` [Caml-list] Writing Identity Functors (or Wrapper modules) in OCAML Jean-Christophe Filliatre
  1 sibling, 1 reply; 5+ messages in thread
From: Julien Signoles @ 2006-02-27 15:04 UTC (permalink / raw)
  To: Merijn de Jonge; +Cc: caml-list

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

You have to explicitely define Hello and World in the wrapper. Try this :

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


Hope this helps,
Julien Signoles
-- 
mailto:Julien.Signoles@lri.fr ; http://www.lri.fr/~signoles
"In theory, practice and theory are the same,
but in practice they are different" (Larry McVoy)


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

* Re: [Caml-list] Writing Identity Functors (or Wrapper modules) in OCAML
  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:06 ` Jean-Christophe Filliatre
  1 sibling, 0 replies; 5+ messages in thread
From: Jean-Christophe Filliatre @ 2006-02-27 15:06 UTC (permalink / raw)
  To: Merijn de Jonge; +Cc: caml-list


Merijn de Jonge writes:
 > 
 > I've problems in writing an Identity Functor in OCAML that I want to use as
 > a wrapper module.

A type representation is missing: you should write your wrapper as

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

See the paragraph "Re-exported variant type or record type: an
equation, a representation." in section 6.8.1 of the Ocaml manual
(http://caml.inria.fr/pub/docs/manual-ocaml/manual016.html)

Hope this helps,
-- 
Jean-Christophe Filliâtre (http://www.lri.fr/~filliatr)


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

* Re: [Caml-list] Writing Identity Functors (or Wrapper modules)  inOCAML
  2006-02-27 15:04 ` [Caml-list] " Julien Signoles
@ 2006-02-27 15:13   ` Sebastian Egner
  2006-02-27 15:20     ` Merijn de Jonge
  0 siblings, 1 reply; 5+ messages in thread
From: Sebastian Egner @ 2006-02-27 15:13 UTC (permalink / raw)
  To: caml-list; +Cc: Merijn de Jonge, merijn.de.jonge

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

> >       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
> 
> You have to explicitely define Hello and World in the wrapper. Try this 
:
> 
> module Wrapper(X:IHelloWorld): IHelloWorld =
> struct
>   type helloWorldType = X.helloWorldType = Hello | Word
>   let hello = X.hello
> end

Alternatively, you have defined too much In IHelloWorld
(depends on what you wanted to do in the first place).
Then try this:

      module type IHelloWorld =
      sig
        type helloWorldType (* now abstract *)
        val hello : unit -> helloWorldType 
      end

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

        ...

Sebastian Egner.

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

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

* Re: [Caml-list] Writing Identity Functors (or Wrapper modules) inOCAML
  2006-02-27 15:13   ` [Caml-list] Writing Identity Functors (or Wrapper modules) inOCAML Sebastian Egner
@ 2006-02-27 15:20     ` Merijn de Jonge
  0 siblings, 0 replies; 5+ messages in thread
From: Merijn de Jonge @ 2006-02-27 15:20 UTC (permalink / raw)
  To: caml-list

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

Hi guys,

Thank you all for the quick reply.

I overlooked the paragraph "Re-exported variant type or record type: an
equation, a representation."  Adding the "type representation" did the
trick.
I needed a concrete type, so the solution to make it abstract is not
appropriate in my case.

Thanks agin.

Merijn de Jonge


On 2/27/06, Sebastian Egner <sebastian.egner@philips.com> wrote:
>
>
> > >       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
> >
> > You have to explicitely define Hello and World in the wrapper. Try this
> :
> >
> > module Wrapper(X:IHelloWorld): IHelloWorld =
> > struct
> >   type helloWorldType = X.helloWorldType = Hello | Word
> >   let hello = X.hello
> > end
>
> Alternatively, you have defined too much In IHelloWorld
> (depends on what you wanted to do in the first place).
> Then try this:
>
>       module type IHelloWorld =
>       sig
>         type helloWorldType (* now abstract *)
>         val hello : unit -> helloWorldType
>       end
>
>       module Wrapper (X: IHelloWorld) :
>         (IHelloWorld with type helloWorldType = X.helloWorldType) =
>       struct
>         type helloWorldType = X.helloWorldType
>         let hello = X.hello
>       end
>
>         ...
>
> Sebastian Egner.

[-- Attachment #2: Type: text/html, Size: 3103 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).