I have two modules which imports each other. Haskell doesn’t support recursive modules. So how can i rewrite my data types without needs circular module system.
Here is my Character.hs
module Character where
import ItemSystem
data Character = Character { name :: String, items :: [Item] }
an here is ItemSystem.hs
module Item where
import Character
data ItemEffect = CharacterEffect (Character -> Character)
| ItemEffect (Item -> Item)
data Item = Item { name :: String, weight :: Int, effect :: ItemEffect }
UPDATE: I will write my all datatypes into one module 🙁 .
Create a third module for the mutually dependent parts:
Then import it from both the other modules and optionally re-export the stuff you want available from each:
If this is in a Cabal package, you can then hide the
Internalmodule from the rest of the world by putting it in theOther-modulessection instead ofExported-modules.For completeness: GHC does support mutually recursive modules, but I would not recommend that for simple cases like this.