From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id C319D7F790 for ; Thu, 24 Apr 2014 16:44:04 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of goswin-v-b@web.de) identity=pra; client-ip=212.227.15.3; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="goswin-v-b@web.de"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of goswin-v-b@web.de) identity=mailfrom; client-ip=212.227.15.3; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="goswin-v-b@web.de"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mout.web.de) identity=helo; client-ip=212.227.15.3; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="postmaster@mout.web.de"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhABAE0iWVPU4w8DnGdsb2JhbABZyGKBGRYOAQEBAQEGDQkJFCiCJQEBBAEnE0QLCxgJJQ8FKIhgAQwMxA4fhw4Xjl8Wgw6BFQSYdIZFEo8z X-IPAS-Result: AhABAE0iWVPU4w8DnGdsb2JhbABZyGKBGRYOAQEBAQEGDQkJFCiCJQEBBAEnE0QLCxgJJQ8FKIhgAQwMxA4fhw4Xjl8Wgw6BFQSYdIZFEo8z X-IronPort-AV: E=Sophos;i="4.97,919,1389740400"; d="scan'208";a="70078398" Received: from mout.web.de ([212.227.15.3]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 24 Apr 2014 16:44:04 +0200 Received: from frosties.localnet ([78.43.112.61]) by smtp.web.de (mrweb001) with ESMTPSA (Nemesis) id 0MZUnl-1WKRWI2wA9-00LCKa for ; Thu, 24 Apr 2014 16:44:03 +0200 Received: from mrvn by frosties.localnet with local (Exim 4.80) (envelope-from ) id 1WdKsd-00018F-14 for caml-list@inria.fr; Thu, 24 Apr 2014 16:44:03 +0200 Date: Thu, 24 Apr 2014 16:44:02 +0200 From: Goswin von Brederlow To: caml-list@inria.fr Message-ID: <20140424144402.GB3845@frosties> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Provags-ID: V03:K0:3a6CXFJfuVs2llni67QW//n2XVVHfDwMTIuyaKdNAmdOVZv+zpW GcMYQpN/907VbwDVx6IMqbOizvLHU0XRRIEchrMoD+DqfcIo9hsAlTV/nwNGUV1Bdqq03sB DH365oolk5nT3YJSW05RooWFmQSHpExQe1NRaLXfVylYC3D0Kzqk4pxERzAiDG3JoEyxPq9 Fcrou1dfNm69w/U8zR3pA== Subject: Re: [Caml-list] Module inside an object On Wed, Apr 23, 2014 at 11:50:00AM +0200, Pierre-Alexandre Voye wrote: > Hello, > I would like to define a parameterized module inside an object by the type > of this object. > > > I have two module interlocked : > > (* Parameters*) > module type A = sig > type agent > type intern_agent = { i : agent} > val create : agent -> intern_agent > end > > module type E = sig > type event > end > > > > module type StateType = sig > > type agent > type event > > type state_t = { > mutable name : string; > mutable parentstate : state_t option; > } > end > > > module State (A : A) (E : E) = struct > > type agent = A.agent > type event = E.event > type state_t = { > mutable name : string; > mutable parentstate : state_t option; > } > > > (*...*) > end > > > > module Agent (S : StateType) = > struct > type agent = S.agent > type event = S.event > type state_t = S.state_t > > type agent_t = { > mutable agent : agent ; > } > > let create a1 = { > agent = a1; > } > end > > > (* An implementation of E*) > type event1 = Event1 | Event2;; > module E = struct type event = event1 end;; > > > > > What I would like to do is something like that (which is syntacticly > incorrect but represents what I would like to do) : > > > class character = object (self :'self) > val mutable position = (0,0) > val agent = > let A = (module Ag = struct > type agent = 'self > type intern_agent = { i : agent} > let create a = { i = a } > end) > in > let Ag = (module Agent(State(A)(E)) ) in 1) I think this creates a new module for every character. I don't think that is what you want since that would make all characters incompatible (and you would have to make the character polymorphic or wrap it in a functor or something). Maybe try: class character = let A = ... let Ag = ... in object (self :'self) ... > Ag.create self > > method getPosition = position > > end;; > > How can I write this to be able to define a value which is an Agent > parametrized by itself ? > > Thank you, 2) I think you can't use "Ag.create self" because that requires passing the self as argument to a function before it has finished being created. You can make agent a mutable 'a option, create it as None and then use an initializer to change it to "Ag.create self". You can avoid the option with a dummy agent (Obj.magic 0 worst case). 3) This looks like a recursive type between a module and an object. That doesn't work. You can only have recursive modules. So you need to wrap the object into a seperate module. Note: recursive modules require a full signature for each module so you have to write a signature for your object. MfG Goswin