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=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by yquem.inria.fr (Postfix) with ESMTP id BE655BBAF for ; Fri, 25 Sep 2009 22:11:02 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AvUBAO7AvEpV2gB5mWdsb2JhbACbAgEBAQEBCAsKBxO7YoImgXgF X-IronPort-AV: E=Sophos;i="4.44,453,1249250400"; d="scan'208";a="36852147" Received: from emailfrontal2.citycable.ch ([85.218.0.121]) by mail1-smtp-roc.national.inria.fr with SMTP; 25 Sep 2009 22:11:02 +0200 Received: from [192.168.0.10] (unknown [85.218.92.99]) (Authenticated sender: guillaume.yziquel@citycable.ch) by emailfrontal2.citycable.ch (Postfix) with ESMTPA id 43D598343DD; Fri, 25 Sep 2009 22:10:57 +0200 (CEST) Message-ID: <4ABD22C6.1070503@citycable.ch> Date: Fri, 25 Sep 2009 22:06:30 +0200 From: Guillaume Yziquel Reply-To: guillaume.yziquel@citycable.ch User-Agent: Mozilla-Thunderbird 2.0.0.19 (X11/20090103) MIME-Version: 1.0 To: Hugo Ferreira Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Cannot safely evaluate the definition of the recursively-defined module References: <49C0E44F.6040603@inescporto.pt> <49C1FDBA.5090809@inescporto.pt> In-Reply-To: <49C1FDBA.5090809@inescporto.pt> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Spam: no; 0.00; guillaume:01 guillaume:01 recursive:01 checker:01 recursive:01 submodule:01 functors:01 run-time:01 sig:01 val:01 val:01 struct:01 pervasives:01 elt:01 sig:01 Hello. Sorry for reviving this short thread. I have the same error message, but=20 I really do not understand what "safety" means in this context. If I specify the signature of the recursive module, shouldn't the type=20 checker work out right out of the box? Sorry, but I'm a bit confused. You'll find the recursive submodule that=20 I'm having problems with below Hugo's email. All the best, Guillaume Yziquel. Hugo Ferreira a =C3=A9crit : > 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 modu= le >>> (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= =20 >> get around the restriction by splitting the module into a=20 >> (recursively-)safe module, and an extension that adds the constants. =20 >> Here is a slightly modified version of your code showing the=20 >> transformation: >> >=20 > Ok, I understand this. >=20 > Thanks, > Hugo F. >=20 >=20 >> ---- >> module type AA_Safe =3D >> sig >> type q >> type t =3D 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 =3D ASet.t =3D >> struct >> type q =3D ASet.t >> type t =3D string >> let compare s1 s2 =3D Pervasives.compare s1 s2 >> let add e s =3D ASet.add e s >> end >> and ASet : Set.S with type elt =3D A1.t =3D Set.Make(A1) >> >> (* now create the full module *) >> module type AA =3D sig >> include AA_Safe >> val empty: q >> end >> >> module A2 : AA =3D struct >> include A1 >> let empty =3D ASet.empty >> end >> >> module type Wrap_A =3D >> sig >> type t >> type q >> >> val init: q >> val add: t -> q -> q >> end >> module Make_A (An_A : AA) : Wrap_A >> =3D >> struct >> type t =3D An_A.t >> type q =3D An_A.q >> >> (*let init =3D ASet.empty*) >> let init =3D An_A.empty >> let add t q =3D An_A.add t q >> end >> >> module Wrap_A1 =3D Make_A( A2 ) >> ---- >> >> Cheers, >> -Mike Here's my recursive submodule: > module rec Registry : sig >=20 > val new_status_signal : t -> status React.signal > val registry : (t * status React.signal) list React.signal > val status_of_agent : t -> status >=20 > end =3D struct=20 >=20 > let new_status_signal agent =3D React.S.fold > begin function current_status -> function > | AgentPresent (agent_of_signal, status_information) -> > begin match agent =3D agent_of_signal with > | false -> current_status > | true -> status_information > end > | AsteriskStatus (Asterisk.Active activity) -> > let agent_ip =3D match Registry.status_of_agent agent with > | Present ip -> Some ip > | Online (ip, _) -> Some ip > | _ -> None in > begin match agent_ip with None -> current_status > | Some ip -> current_status (* To do... *) > end > | AsteriskStatus _ -> current_status > end Offline (React.E.select [ > agent_status_notification; > (React.E.map begin function s -> AsteriskStatus s end > (Asterisk.server # status_change)) > ]) >=20 > let registry =3D React.S.fold > begin fun live_registry new_agent -> new_agent::live_registry end > begin Lwt_main.run (persistent_registry >>=3D Ocsipersist.get >>=3D > begin function a_list -> Lwt.return (List.map > begin function (nom, prenom) -> > let a =3D {nom =3D nom; prenom =3D prenom} in > a, (Registry.new_status_signal a) > end a_list) > end) > end > begin React.E.map > begin function agent -> agent, (Registry.new_status_signal agent)= end > adding_to_registry > end >=20 > let status_of_agent agent =3D > try React.S.value (List.assoc agent (React.S.value Registry.registr= y)) > with Not_found -> raise (invalid_arg ("Agent.status_of_agent: "^age= nt.prenom^" "^agent.nom)) >=20 > end --=20 Guillaume Yziquel http://yziquel.homelinux.org/