From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: ** X-Spam-Status: No, score=2.8 required=5.0 tests=DNS_FROM_RFC_POST, HTML_MESSAGE,SPF_NEUTRAL autolearn=disabled version=3.1.3 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id 40917BBC4 for ; Wed, 18 Mar 2009 13:48:16 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjcDACOKwEnRVdulmGdsb2JhbACCIy+KMYgsPwEBAQEBCAkMBxGsS5BCAQMBA4N5BoVR X-IronPort-AV: E=Sophos;i="4.38,384,1233529200"; d="scan'208";a="22751499" Received: from mail-ew0-f165.google.com ([209.85.219.165]) by mail2-smtp-roc.national.inria.fr with ESMTP; 18 Mar 2009 13:48:15 +0100 Received: by ewy9 with SMTP id 9so30566ewy.27 for ; Wed, 18 Mar 2009 05:48:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:in-reply-to :references:date:x-google-sender-auth:message-id:subject:from:to :content-type; bh=qhrtmhf3/GUzfDIXfPSCJHm7ZN5yh2PXylu4z5F2MnI=; b=aj5wQcICMKfURRo/s6R3u/UKONruI07yVg1dw9IEgEN/Zl+22hyLKRUMKXvrix8xSv 8QDczd+Wb4mNbzBOLrTs78zF8w2u0Q4x+cbb9/fHU8kJG5Jy2i0zQVo2WvIyMympUXWz 298D9KxRAOJPpGofQl9lGZ+TAcwbqTPgUuNuk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:content-type; b=ntTkErCc+Rk9X/tNLdqNLYxFvM7R2nqQ6spUV+VPml5KaUbee5mEAbi6gP+efA3uSN LVgDYHXeEWGFWfrVDnyFXpYTgrw1caJncECJFEbo4qeSS6Kn+bhZZnmXQkCEX3RlIXeb rQr32KXZxLHEBaoLxiUNJ56N5/9lybUEGemok= MIME-Version: 1.0 Sender: alpmestan@gmail.com Received: by 10.210.139.15 with SMTP id m15mr934435ebd.34.1237380495719; Wed, 18 Mar 2009 05:48:15 -0700 (PDT) In-Reply-To: <49C0E44F.6040603@inescporto.pt> References: <49C0E44F.6040603@inescporto.pt> Date: Wed, 18 Mar 2009 13:48:15 +0100 X-Google-Sender-Auth: e6b13ba1f2fd2f7a Message-ID: Subject: Re: [Caml-list] Cannot safely evaluate the definition of the recursively-defined module From: Alp Mestan To: caml-list@yquem.inria.fr Content-Type: multipart/alternative; boundary=0015174c1778e63c1804656418f0 X-Spam: no; 0.00; struct:01 functors:01 run-time:01 compiler:01 sig:01 val:01 val:01 struct:01 pervasives:01 elt:01 sig:01 beginner's:01 ocaml:01 bug:01 functors:01 --0015174c1778e63c1804656418f0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Hi, replacing : module rec A1 : AA = struct type q = ASet.t type t = string with : module rec A1 : AA with type q = ASet.t, type t = string should be okay. Shouldn't it ? On Wed, Mar 18, 2009 at 1:08 PM, Hugo Ferreira wrote: > Hello, > > I hope this is not a beginners questions. > I am trying to reuse code via functors, > however I am getting the following error: > > Cannot safely evaluate the definition of the recursively-defined module > (refers to "AA.empty" when implemented as a constant value) > > I circumvented the problem by not using a > constant value but a function instead. As I > understand it this may cause run-time errors. > My question is: is their any way to make the > following example work. > > Specifically, for the example below is their > any way of indicating to the compiler that > AA.q = ASet.t ? > > TIA, > Hugo F. > > module type AA = > sig > type q > type t = string > > val compare: t -> t -> int > val add: t -> q -> q > val empty: unit -> q > end > > module rec A1 : AA > = struct > type q = ASet.t > type t = string > > let compare s1 s2 = Pervasives.compare s1 s2 > let add e s = ASet.add e s > let empty _ = ASet.empty > end > and ASet : Set.S with type elt = A1.t > = Set.Make(A1) > > module type Wrap_A = > sig > type t > type q > > val init: q > val add: t -> q -> q > end > > module Make_A (An_A : AA) : Wrap_A > = > struct > type t = An_A.t > type q = An_A.q > > (*let init = ASet.empty*) > let init = An_A.empty () > let add t q = An_A.add t q > end > > module Wrap_A1 = Make_A( A1 ) > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > -- Alp Mestan In charge of the C++ section on Developpez.com. --0015174c1778e63c1804656418f0 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi,

replacing :
module rec A1 : AA
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =3D struct
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 type q =3D ASet.t
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 type t =3D string

with :module rec A1 : AA with type q =3D ASet.t, type t =3D string

should= be okay. Shouldn't it ?

On Wed, Mar = 18, 2009 at 1:08 PM, Hugo Ferreira <hmf@inescporto.pt> wrote:
Hello,

I hope this is not a beginners questions.
I am trying to reuse code via functors,
however I am getting the following error:

Cannot safely evaluate the definition of the recursively-defined module
(refers to "AA.empty" when implemented as a constant value)

I circumvented the problem by not using a
constant value but a function instead. As I
understand it this may cause run-time errors.
My question is: is their any way to make the
following example work.

Specifically, for the example below is their
any way of indicating to the compiler that
AA.q =3D ASet.t ?

TIA,
Hugo F.

module type AA =3D
=A0sig
=A0 =A0type q
=A0 =A0type t =3D string

=A0 =A0val compare: t -> t -> int
=A0 =A0val add: t -> q -> q
=A0 =A0val empty: unit -> q
=A0end

module rec A1 : AA
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =3D struct
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 type q =3D ASet.t
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 type t =3D string

=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 let compare s1 s2 =3D Pervasives.c= ompare s1 s2
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 let add e s =3D ASet.add e s
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 let empty _ =3D ASet.empty
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 end
=A0 =A0 =A0 =A0and ASet : Set.S with type elt =3D A1.t
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =3D Set.Make(A1)

module type Wrap_A =3D
=A0sig
=A0 =A0type t
=A0 =A0type q

=A0 =A0val init: q
=A0 =A0val add: t -> q -> q
=A0end

module Make_A (An_A : AA) : Wrap_A
=A0=3D
=A0struct
=A0 =A0type t =3D An_A.t
=A0 =A0type q =3D An_A.q

=A0 =A0(*let init =3D ASet.empty*)
=A0 =A0let init =3D An_A.empty ()
=A0 =A0let add t q =3D An_A.add t q
end

module Wrap_A1 =3D Make_A( A1 )

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list Archives: http://caml.in= ria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs



--
Alp Mestan
In charge= of the C++ section on Developpez.com.
--0015174c1778e63c1804656418f0--