Réf. : [Haskell-cafe] Re: circular imports
That sort of code (stripped out): In Game.hs: data Game = Game { ... activeRules :: [Rule]} applyTo :: Rule - Game - Game applyTo r gs = ... In Rule.hs: data Rule = Cond (Obs) Rule Rule | many others.. deriving (Read, Show, Eq, Typeable) data NamedRule = NamedRule { ..., rule :: Rule } isRuleLegal :: Rule - NamedRule - Game - Bool isRuleLegal = ... In Obs.hs: data Obs a where ProposedBy :: Obs Int -- The player that proposed the tested rule ... evalObs :: Obs - NamedRule - Game - EvalObsType evalObs = ... Corentin Johannes Waldmann waldm...@imn.ht Pour wk-leipzig.dehaskell-cafe@haskell.org Envoyé par : cc haskell-cafe-bou n...@haskell.orgObjet [Haskell-cafe] Re: circular imports 07/09/2010 14:00 corentin.dupont at ext.mpsa.com writes: I had recently a really hard time splitting up my program into parts! The natural, business-oriented split up drove me into a deadly circular dependency. perhaps you could post your code (enough of it to understand the problem)? J.W. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Réf. : [Haskell-cafe] Re: circular imports
corentin.dup...@ext.mpsa.com schrieb: That sort of code (stripped out): In Game.hs: data Game = Game { ... activeRules :: [Rule]} applyTo :: Rule - Game - Game applyTo r gs = ... In Rule.hs: data Rule = Cond (Obs) Rule Rule | many others.. deriving (Read, Show, Eq, Typeable) data NamedRule = NamedRule { ..., rule :: Rule } isRuleLegal :: Rule - NamedRule - Game - Bool isRuleLegal = ... In Obs.hs: data Obs a where ProposedBy :: Obs Int -- The player that proposed the tested rule ... evalObs :: Obs - NamedRule - Game - EvalObsType evalObs = ... As I see there is no cycle in the types. How about defining Game, Rule, Obs in private modules, like Private.Game, Private.Rule, Private.Obs, and implementing the functions in public modules like Game, Rule, Obs ? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Réf. : [Haskell-cafe] Re: circular imports
That sort of code (stripped out): In Game.hs: data Game = Game { ... activeRules :: [Rule]} applyTo :: Rule - Game - Game applyTo r gs = ... Often, it helps to parameterize the types/functions (instead of using recursive modules to hardcode the parameters). Would something like this work for your case (taking the Game module out of the loop)? data Game rule = Game { ... activeRules :: [rule]} applyTo :: rule - Game rule - Game rule applyTo r gs = ... In Rule.hs: .. isRuleLegal :: Rule - NamedRule - Game Rule - Bool isRuleLegal = ... In Obs.hs: evalObs :: Obs - NamedRule - Game Rule - EvalObsType evalObs = ... For the record, I'd like to have recursive modules without having to go outside the language (some standardized notion of Haskell module interfaces would be nicer than implementation-specific boot files). But I'd like to have parameterized modules even more, as that would allow me to avoid many use cases of recursive modules (again, that would seem to require module interfaces). Claus ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe