* [Caml-list] Module/Functor modelisation @ 2002-08-14 7:07 Johan Baltié [not found] ` <20020814074250.GA6002@barcelona.lrde.epita.fr> 0 siblings, 1 reply; 6+ messages in thread From: Johan Baltié @ 2002-08-14 7:07 UTC (permalink / raw) To: caml-list Hi ! I have a simple functor: module type Used = sig type output val toto : int -> output -> output val tutu : double -> output -> output end module type User = functor (U : Used) -> sig val toto : int -> U.output -> U.output val tutu : double -> U.output -> U.output end And User is implemented by two types doing mostly the same things with different init, and with recursive and/or mutual call in toto an tutu. I'd like to factorize the shared code, BUT the recursive call prevent me of doing this. Here an implementation example of the part where the problem lie: module User1: User = functor (U : Used) -> struct let toto i output = let val = U.tutu 12.0 output in tutu 12.0 val let rec tutu d output = if (d = 11.0) then output else tutu (d -. 1.0) (U.toto 1 output) end module User2: User = functor (U : Used) -> struct let toto i output = let val = tutu 12.0 output in U.tutu 12.0 val let rec tutu d output = if (d = 11.0) then output else let val = tutu (d -. 1.0) output in U.toto 1 val end Basicly I once do things in a Prefix way, and once in a postfix way. I would like to call in User toto and tutu function like: let toto i data = Used.tutu 12.0 data let tutu d output = User.tutu (d -. 1.0) output My problem lays here. I cannot now which User.tutu to call. If I try to make a functor that do take a User module, there is a recursion problem as this functor will need a User module and the user module will need this functor to be able to call the helping functions ! It's gaving me headache.... I know this explanation is not really clear, but I tried to simplify my problem in order to explain it and I fear people won't see any usefullness in my needs. Thanks in advance Ciao Jo ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners ^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <20020814074250.GA6002@barcelona.lrde.epita.fr>]
[parent not found: <20020814074844.M48926@epita.fr>]
* Fw: Re: [Caml-list] Module/Functor modelisation [not found] ` <20020814074844.M48926@epita.fr> @ 2002-08-14 7:49 ` Johan Baltié [not found] ` <20020814083553.GC6002@barcelona.lrde.epita.fr> 0 siblings, 1 reply; 6+ messages in thread From: Johan Baltié @ 2002-08-14 7:49 UTC (permalink / raw) To: caml-list Uh.. My code was not caml compliant :) But no that's not my main problem. I thing i cannot go without giving my real code: Here is it: -------- module type Visitor = sig type output val behavior : behavior -> output -> output val pattern_action : pattern_action -> output -> output val pattern : pattern -> output -> output val action : action -> output -> output val ident_regex : ident_regex -> output -> output val message : message -> output -> output val message_body: message_body -> output -> output val declaration : declaration -> output -> output val types : types -> output -> output val ident : ident -> output -> output val expression : expression -> output -> output val litteral : litteral -> output -> output end (* Traverser type *) module type Traverse = functor (Av : Visitor) -> sig val behavior : behavior -> Av.output -> Av.output val pattern_action : pattern_action -> Av.output -> Av.output val pattern : pattern -> Av.output -> Av.output val action : action -> Av.output -> Av.output val ident_regex : ident_regex -> Av.output -> Av.output val message : message -> Av.output -> Av.output val message_body: message_body -> Av.output -> Av.output val declaration : declaration -> Av.output -> Av.output val types : types -> Av.output -> Av.output val ident : ident -> Av.output -> Av.output val expression : expression -> Av.output -> Av.output val litteral : litteral -> Av.output -> Av.output end (* Traverser implementation *) module PrefixTraverse = functor (Av : Visitor) -> struct let ident i data = Av.ident i data let rec types t data = let output = Av.types t data in match t with | SimpleType(id) -> ident id output | TypesList(t1, t2) -> types t2 (types t1 output) let rec ident_regex i data = let output = Av.ident_regex i data in match i with | Underscore -> output | Ident(id) -> ident id output | IdentRegexList(id1, id2) -> ident_regex id2 (ident_regex id1 output) let rec declaration d data = let output = Av.declaration d data in match d with | DeclarationConstant(l) -> litteral l output | DeclarationVariable(t, id) -> ident_regex id (types t output) | DeclarationList(d1, d2) -> declaration d2 (declaration d1 output) and pattern p data = let output = Av.pattern p data and (id1, id2, decl) = p in declaration decl (ident_regex id2 (ident_regex id1 output)) and message m data = let output = Av.message m data in match m with | UnansweredMessage(mb) -> message_body mb output | AnsweredMessage(mb, id) -> ident id (message_body mb output) | MessageList (m1, m2) -> message m2 (message m1 output) and message_body m data = let output = Av.message_body m data in match m with | NamedMessage(id, e) -> expression e (ident id output) | AnonymousMessage(e) -> expression e output and litteral l data = let output = Av.litteral l data in match l with | Message(m) -> message m output | _ -> output and expression e data = let output = Av.expression e data in match e with | ExpressionConstant(l) -> litteral l output | ExpressionVariable(i) -> ident i output | ExpressionList(e1, e2) -> expression e2 (expression e1 output) let action a data = let output = Av.action a data and (m, e) = a in expression e (message m output) let rec pattern_action p data = let output = Av.pattern_action p data in match p with | PatternAction(pat, act) -> action act (pattern pat output) | PatternActionList(pa1, pa2) -> pattern_action pa2 (pattern_action pa1 output) let behavior b data = let output = Av.behavior b data in match b with | InheritedBehavior(name, inherited, pas) -> pattern_action pas (ident inherited (ident name output)) | RootedBehavior(name, pas) -> pattern_action pas (ident name output) end (* Traverser implementation *) module PostfixTraverse = functor (Av : Visitor) -> struct let ident i data = Av.ident i data let rec types t data = let output = match t with | SimpleType(id) -> ident id data | TypesList(t1, t2) -> types t2 (types t1 data) in Av.types t output let rec ident_regex i data = let output = match i with | Underscore -> data | Ident(id) -> ident id data | IdentRegexList(id1, id2) -> ident_regex id2 (ident_regex id1 data) in Av.ident_regex i output let rec declaration d data = let output = Av.declaration d data in match d with | DeclarationConstant(l) -> litteral l output | DeclarationVariable(t, id) -> ident_regex id (types t output) | DeclarationList(d1, d2) -> declaration d2 (declaration d1 output) and pattern p data = let output = Av.pattern p data and (id1, id2, decl) = p in declaration decl (ident_regex id2 (ident_regex id1 output)) and message m data = let output = Av.message m data in match m with | UnansweredMessage(mb) -> message_body mb output | AnsweredMessage(mb, id) -> ident id (message_body mb output) | MessageList (m1, m2) -> message m2 (message m1 output) and message_body m data = let output = Av.message_body m data in match m with | NamedMessage(id, e) -> expression e (ident id output) | AnonymousMessage(e) -> expression e output and litteral l data = let output = Av.litteral l data in match l with | Message(m) -> message m output | _ -> output and expression e data = let output = Av.expression e data in match e with | ExpressionConstant(l) -> litteral l output | ExpressionVariable(i) -> ident i output | ExpressionList(e1, e2) -> expression e2 (expression e1 output) let action a data = let output = Av.action a data and (m, e) = a in expression e (message m output) let rec pattern_action p data = let output = Av.pattern_action p data in match p with | PatternAction(pat, act) -> action act (pattern pat output) | PatternActionList(pa1, pa2) -> pattern_action pa2 (pattern_action pa1 output) let behavior b data = let output = Av.behavior b data in match b with | InheritedBehavior(name, inherited, pas) -> pattern_action pas (ident inherited (ident name output)) | RootedBehavior(name, pas) -> pattern_action pas (ident name output) end -------- As I said, my problem is that I'm doing the same job once in a prefix way and once in a postfix way. In pattern_action i'd like to have: "match p with | PatternAction(pat, act) -> action act (pattern pat output) | PatternActionList(pa1, pa2) -> pattern_action pa2 (pattern_action pa1 output)" Factorized from Prefix and Postfix. Does it enlight my dark explanation ? > On Wed, Aug 14, 2002 at 08:07:53AM +0100, Johan Baltié wrote: > > Hi ! > > > > I have a simple functor: > > [..] > > I do not know if I have understood your problem but try > something like that: > > module type Used = > sig > type output > > val toto : int -> output -> output > val tutu : float -> output -> output > end > > module type User = > functor (U : Used) -> > sig > > val toto : int -> U.output -> U.output > val tutu : float -> U.output -> U.output > end > > module User1: User = > functor (U : Used) -> > struct > let rec toto i output = > let v = U.tutu 12.0 output > in > tutu 12.0 v > and tutu d output = > if (d = 11.0) then > output > else > tutu (d -. 1.0) (U.toto 1 output) > end > > module User2: User = > functor (U : Used) -> > struct > let rec toto i output = > let v = tutu 12.0 output > in > U.tutu 12.0 v > and tutu d output = > if (d = 11.0) then > output > else > let v = tutu (d -. 1.0) output > in > U.toto 1 v > end > > -- > Yann Régis-Gianas. Ciao Jo ------- End of Forwarded Message ------- Ciao Jo ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners ^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <20020814083553.GC6002@barcelona.lrde.epita.fr>]
[parent not found: <20020814083157.M89732@wanadoo.fr>]
[parent not found: <20020814090548.GD6002@barcelona.lrde.epita.fr>]
[parent not found: <20020814085806.M98813@wanadoo.fr>]
* Re: [Caml-list] Module/Functor modelisation [not found] ` <20020814085806.M98813@wanadoo.fr> @ 2002-08-14 9:33 ` Yann Régis-Gianas [not found] ` <20020814093239.M61475@wanadoo.fr> 0 siblings, 1 reply; 6+ messages in thread From: Yann Régis-Gianas @ 2002-08-14 9:33 UTC (permalink / raw) To: Johan Baltié; +Cc: caml-list On Wed, Aug 14, 2002 at 09:58:06AM +0100, Johan Baltié wrote: > Mon probleme tient effectivement dans l'utilisation d'un autre functor. > > Appellons le GenericTraverse: > > module GenericTraverse = > functor (T : Traverse) -> > functor (Av: Visitor) -> > struct > ..... > let pattern_action p data = > match p with > | PatternAction(pat, act) -> > T.action act (T.pattern pat data) > | PatternActionList(pa1, pa2) -> > T.pattern_action pa2 (T.pattern_action pa1 data) > .... > end > > > Le probleme est maintenant comment l'utiliser ??? > > module PostfixTraverse = ???? > struct > > let pattern_action p data = > let output = Av.pattern_action p data > in > GenericTraverse.pattern_action p output > end > Ce que tu es en train de faire, ca s'appelle des modules mixins et malheuresement Objective Caml ne le gère pas pour le moment. Par contre, est-ce que tu ne voudrais pas faire un truc du style: module type TraverseWithoutPatternAction = sig (* ce qui ne dépend pas de pattern_action *) end module PostfixTraverse (T : TraverseWithoutPatternAction) (Av: Visitor) = struct let pattern_action p data = (* ... *) end module type TraverseType = sig val pattern_action : (* .. *) end module FinalTraverse (T : TraverseType) = struct (* ce qui dépend de pattern action *) end -- Yann Régis-Gianas. ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners ^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <20020814093239.M61475@wanadoo.fr>]
* Re: [Caml-list] Module/Functor modelisation [not found] ` <20020814093239.M61475@wanadoo.fr> @ 2002-08-14 10:00 ` Yann Régis-Gianas 0 siblings, 0 replies; 6+ messages in thread From: Yann Régis-Gianas @ 2002-08-14 10:00 UTC (permalink / raw) To: Johan Baltié; +Cc: caml-list On Wed, Aug 14, 2002 at 10:32:39AM +0100, Johan Baltié wrote: > Ce n'est malheureusement pas faisable parce qu'il me faudrait le faire pour > *tous* les types (à l'exception des types feuilles de mon AST, ce qui m'en fait > 2 en moins) et comme certains types sont mutuellement recursifs ca coince.... Alors, je ne vois plus de solution. > > En fait il me manque l'extension de module avec module partiellement defini. Tu veux dire des modules avec des valeurs différées ? Ce sont des modules mixins. Allez hop, regarde ces articles pour te faire une idée de la chose : http://pauillac.inria.fr/~xleroy/publi/mixins-cbv-esop2002.pdf ftp://ftp.disi.unige.it/pub/personÅnconaD/DISI-TR-99-05.ps.gz > Ou alors il y a un moyen de *simuler* ceci, mais je ne vois pas comment Malheuresement non, il n'y a pas moyen car le système de modules tel qu'il est fait ne supporte que les relations d'importations qui forment un graphe acyclique. Il va falloir que tu continues avec la méthode du départ ou bien que tu changes de modélisation. -- Yann Régis-Gianas. ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Caml-list] Module/Functor modelisation @ 2002-08-14 6:55 Johan Baltié 2002-08-14 7:10 ` Johan Baltié 0 siblings, 1 reply; 6+ messages in thread From: Johan Baltié @ 2002-08-14 6:55 UTC (permalink / raw) To: caml-list Hi ! I have a simple functor: module type Used = sig type output val toto : int -> output -> output val tutu : double -> output -> output end module type User = functor (U : Used) -> sig val toto : int -> U.output -> U.output val tutu : double -> U.output -> U.output end And User is implemented by two types doing mostly the same things with different init, and with recursive and/or mutual call in toto an tutu. I'd like to factorize the shared code, BUT the recursive call prevent me of doing this. Here an implementation example of the part where the problem lie: module User1: User = functor (U : Used) -> struct let toto i output = end Ciao Jo ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] Module/Functor modelisation 2002-08-14 6:55 Johan Baltié @ 2002-08-14 7:10 ` Johan Baltié 0 siblings, 0 replies; 6+ messages in thread From: Johan Baltié @ 2002-08-14 7:10 UTC (permalink / raw) To: caml-list Sorry for this one, my webmail is sometimes a bit anoying > Hi ! > > I have a simple functor: > > module type Used = > sig > type output > > val toto : int -> output -> output > val tutu : double -> output -> output > end > > module type User = > functor (U : Used) -> > sig > > val toto : int -> U.output -> U.output > val tutu : double -> U.output -> U.output > end > > And User is implemented by two types doing mostly the same things with > different init, and with recursive and/or mutual call in toto an tutu. > > I'd like to factorize the shared code, BUT the recursive call prevent > me of doing this. Here an implementation example of the part where the > problem lie: > > module User1: User = > functor (U : Used) -> > struct > let toto i output = > > end > > Ciao > > Jo > ------------------- > To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr > Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Ciao Jo ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2002-08-14 9:44 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2002-08-14 7:07 [Caml-list] Module/Functor modelisation Johan Baltié [not found] ` <20020814074250.GA6002@barcelona.lrde.epita.fr> [not found] ` <20020814074844.M48926@epita.fr> 2002-08-14 7:49 ` Fw: " Johan Baltié [not found] ` <20020814083553.GC6002@barcelona.lrde.epita.fr> [not found] ` <20020814083157.M89732@wanadoo.fr> [not found] ` <20020814090548.GD6002@barcelona.lrde.epita.fr> [not found] ` <20020814085806.M98813@wanadoo.fr> 2002-08-14 9:33 ` Yann Régis-Gianas [not found] ` <20020814093239.M61475@wanadoo.fr> 2002-08-14 10:00 ` Yann Régis-Gianas -- strict thread matches above, loose matches on Subject: below -- 2002-08-14 6:55 Johan Baltié 2002-08-14 7:10 ` Johan Baltié
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox