[Haskell-cafe] Avoiding Dependency loops
dct25-561bs at mythic-beasts.com
Sun Oct 25 09:01:57 UTC 2015
Seems reasonable to me. It's a common dependency-breaking technique, akin
to introducing an interface in OO-land. Did you also introduce a typeclass
constraint on the type 'r' so you can call some methods on it too? If not
then Process doesn't really depend on System at all.
Another thing to look for is that perhaps your System module splits into
two bits, one low-level (defining types and so on) and one high-level
(making use of everything in System and Process and Runner) and the two
bits live at opposite ends of the dependency graph. I've found that quite a
common situation to be in when splitting things up into modules too.
On 25 October 2015 at 08:36, martin <martin.drautzburg at web.de> wrote:
> Hello all,
> I just split up a program I'm working on into several source files and ran
> into the following difficulty:
> module Process implements Process which has a field Runner. Runner is a
> basically a function which alters a 'System'
> state. So Process needs Runner, Runner needs System and thus Process needs
> module System implements among others a collection of Processes (because
> Processes can alter their states). So System
> needs Process.
> Eh voila, I have a loop.
> What I did was to leave the type of the Runner unspecified in Process,
> i.e. I now have (Process r) where r is the type
> of the Runner. Thus Process no longer needs to know about System.
> This does work, but it feels strange and I'm a bit worried that this is an
> indication for a design flaw, but I cannot
> see it.
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe