From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 679BBBBBB for ; Mon, 27 Feb 2006 15:49:53 +0100 (CET) Received: from pproxy.gmail.com (pproxy.gmail.com [64.233.166.183]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id k1REnqfH009006 for ; Mon, 27 Feb 2006 15:49:52 +0100 Received: by pproxy.gmail.com with SMTP id s49so745415pyc for ; Mon, 27 Feb 2006 06:49:52 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:mime-version:content-type; b=bjeqmd8YcLUZSIgIQQu1sVnWz8b3cOQWFtdm/xbSAk8kRzOIK4BP5R7XxXJSLxVvahEUSqtW/JZjU6mJPU4egmyWNnENkiLQpBOX+Fbgm1q2SAF+rSaBpnWz9GfDaW01WCzx8hfhdCLIHHYHYcmwImfkGPt3/4AiHmEzFW6Hq3Q= Received: by 10.65.188.15 with SMTP id q15mr4902193qbp; Mon, 27 Feb 2006 06:49:51 -0800 (PST) Received: by 10.64.253.4 with HTTP; Mon, 27 Feb 2006 06:49:51 -0800 (PST) Message-ID: Date: Mon, 27 Feb 2006 15:49:51 +0100 From: "Merijn de Jonge" To: caml-list@yquem.inria.fr Subject: Writing Identity Functors (or Wrapper modules) in OCAML MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_3370_2096655.1141051791204" X-Miltered: at nez-perce with ID 44031190.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; functors:01 ocaml:01 functor:01 ocaml:01 functor:01 sig:01 val:01 struct:01 struct:01 compiler:01 ocamlc:01 mismatch:01 sig:01 val:01 compiler:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: * X-Spam-Status: No, score=1.9 required=5.0 tests=HTML_40_50,HTML_MESSAGE, RCVD_BY_IP,RCVD_IN_BL_SPAMCOP_NET autolearn=disabled version=3.0.3 ------=_Part_3370_2096655.1141051791204 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline 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, th= e module World, an Identity functor defined in the module Wrapper, and the binding of World to Wrapper in the module TestWrapper: module type IHelloWorld =3D sig type helloWorldType =3D Hello | World val hello : unit -> helloWorldType end module Wrapper (X: IHelloWorld) : IHelloWorld =3D struct type helloWorldType =3D X.helloWorldType let hello =3D X.hello end module World : IHelloWorld =3D struct type helloWorldType =3D Hello | World let hello () =3D Hello end module TestWrapper =3D 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 =3D X.helloWorldType val hello : unit -> X.helloWorldType end is not included in IHelloWorld Type declarations do not match: type helloWorldType =3D X.helloWorldType is not included in type helloWorldType =3D Hello | World If I change helloWorldType into "int" and let the definition of hello yield (say) 10: type helloWorldType =3D int let hello () =3D 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 =3D X.helloWorldType =3D 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 ------=_Part_3370_2096655.1141051791204 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hi,

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

Consider the following OCAML definiti= on containing the type IHelloWorld, the module World, an Identity functor= =20
defined in the module Wrapper, and the binding of World to Wrapper in t= he module TestWrapper:

      module type IHelloWorld = =3D
      sig
         t= ype helloWorldType =3D Hello | World
        val hel= lo : unit -> helloWorldType
      end

      module W= rapper (X: IHelloWorld) : IHelloWorld =3D
      struct        type helloWorldType =3D X.helloWorldType<= br>        let hello =3D X.hello
    =   end

      module World : IHelloWorld= =3D
      struct
         type h= elloWorldType =3D Hello | World
         l= et hello () =3D Hello
      end

   =    module TestWrapper =3D 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:
      &nb= sp; sig
          type helloWorldType =3D = X.helloWorldType
          val hello : uni= t -> X.helloWorldType
        end
  =     is not included in
        IHello= World
     Type declarations do not match:
        type helloWorldType =3D X.helloWorldTy= pe
      is not included in
      =   type helloWorldType =3D Hello | World

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

      type helloWorldType =3D int
    &= nbsp; let hello () =3D 10

Then the compiler issues no error at all!<= br>
Using a "with type" construct in the module definition of = Wrapper does not work:

      module Wrapper (X: IHelloWorld) : IHelloWorl= d  with type helloWorldType =3D X.helloWorldType =3D

I don't un= derstand what is going on. Can anyone help me understanding this problem an= d help me
writing a wrapper module as above?

Many thanks in advance

Best regards,
Merijn de Jonge
<= br>




------=_Part_3370_2096655.1141051791204--