[Haskell-beginners] cyclic dependency problem

Konstantin Saveljev konstantin.saveljev at gmail.com
Thu Mar 5 13:43:30 UTC 2015


Hello,

I'm having some trouble with cyclic dependency.

My simplified version of hierarchy:

    module A where

    import MyState

    data A a = A (StateT MyState IO a) deriving (...)

Now there is a module MyState:

    module MyState where

    import SomeType

    data MyState = MyState { st :: SomeType, ... }

Finally the module that introduces cyclic dependency:

    module SomeType where

    import A

    data SomeType = SomeType { f :: A (), ... }

I have been suggested to move the types into one module and then import it
wherever needed. But the problem is that even if I put them into one file
those three data types still form a cyclic dependency and compiler throws
errors saying "i don't know about this"

So if I have a single module:

    data A a = A (StateT MyState IO a) deriving (...)
    data MyState = MyState { st :: SomeType, ... }
    data SomeType = SomeType { f :: A (), ... }

With this setup the compiler is gonna tell us it doesn't know about
MyState. And no matter how we shuffle these types within a file we are
still getting some "unknowns"

How would one approach such a problem?

Best regards,
Konstantin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20150305/5d062b15/attachment.html>


More information about the Beginners mailing list