[Haskell-cafe] n00b circular dep question

Aaron Tomb atomb at galois.com
Fri Apr 25 14:02:33 EDT 2008


On Apr 25, 2008, at 9:54 AM, Jennifer Miller wrote:
> So, I have a circular dependency in my modules that I don't know how  
> to resolve in Haskell. I went looking for the equivalent of #include  
> which is how I would have solved this in C++.  I'm sure there is a  
> simple answer to this and I'm hoping this group can point me in the  
> right direction.

GHC supports CPP, so you could take the same approach in Haskell.

# cat Main.hs
data Foo = Foo { x :: Int, y :: Int } deriving Show

foo = Foo { x = 2,
#include "y.hs"
           }

# cat y.hs
y = (x foo) + 2

# ghci -cpp Main.hs
GHCi, version 6.8.2: http://www.haskell.org/ghc/  :? for help
Loading package base ... linking ... done.
[1 of 1] Compiling Main             ( Main.hs, interpreted )
Ok, modules loaded: Main.
*Main> foo
Foo {x = 2, y = 4}
*Main>

Aaron



More information about the Haskell-Cafe mailing list