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=1.5 required=5.0 tests=AWL,SPF_SOFTFAIL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id C259ABBC4 for ; Thu, 19 Mar 2009 09:09:36 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Am4CALeawUnVhjEYjmdsb2JhbACNBYhuAQEBAQkLCAkPBbwJg3wG X-IronPort-AV: E=Sophos;i="4.38,388,1233529200"; d="scan'208";a="24552700" Received: from ihsmtp02voda.lis.interhost.com (HELO ihsmtp02cons.lis.interhost.com) ([213.134.49.24]) by mail3-smtp-sop.national.inria.fr with ESMTP; 19 Mar 2009 09:09:36 +0100 Received: from [192.168.1.64] ([77.54.249.136]) by ihsmtp02cons.lis.interhost.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 19 Mar 2009 08:06:41 +0000 Message-ID: <49C1FDBA.5090809@inescporto.pt> Date: Thu, 19 Mar 2009 08:09:30 +0000 From: Hugo Ferreira User-Agent: Thunderbird 2.0.0.19 (X11/20090105) MIME-Version: 1.0 To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Cannot safely evaluate the definition of the recursively-defined module References: <49C0E44F.6040603@inescporto.pt> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 19 Mar 2009 08:06:41.0822 (UTC) FILETIME=[A31A6BE0:01C9A869] X-Spam: no; 0.00; functors:01 run-time:01 sig:01 val:01 val:01 struct:01 pervasives:01 elt:01 sig:01 struct:01 cheers:01 -mike:01 beginner's:01 ocaml:01 bug:01 Michael Furr wrote: > > On Wed, 18 Mar 2009, Hugo Ferreira wrote: > >> 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. > > If you only need to store a constant value in the module, then you can > get around the restriction by splitting the module into a > (recursively-)safe module, and an extension that adds the constants. > Here is a slightly modified version of your code showing the > transformation: > Ok, I understand this. Thanks, Hugo F. > ---- > module type AA_Safe = > sig > type q > type t = string > > val compare: t -> t -> int > val add: t -> q -> q > (* omit empty here, since it is not "safe" *) > end > > module rec A1 : AA_Safe with type q = ASet.t = > struct > type q = ASet.t > type t = string > let compare s1 s2 = Pervasives.compare s1 s2 > let add e s = ASet.add e s > end > and ASet : Set.S with type elt = A1.t = Set.Make(A1) > > (* now create the full module *) > module type AA = sig > include AA_Safe > val empty: q > end > > module A2 : AA = struct > include A1 > let empty = ASet.empty > end > > 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( A2 ) > ---- > > Cheers, > -Mike > > _______________________________________________ > 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 >