[Haskell-cafe] n00b circular dep question
Henning Thielemann
lemming at henning-thielemann.de
Fri Apr 25 17:49:04 EDT 2008
On Fri, 25 Apr 2008, Jennifer Miller wrote:
> I have a graph where the nodes contain a number of fields of various types. The values for one of those fields -- call it Mass -- need to reside in a separate file from the main graph definition (this is for workflow reasons and is given to me as a constraint). In order to set the Mass for a particular node, I need access to the other fields of that node. The other constraint is that the graph needs to be available in an interpreter (eg GHCi).
>
> 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.
Sometimes circular module dependencies can be solved by using a type parameter.
mutually recursive:
module A where
data LabeledTree label = LabeledTree label (Tree label)
module B where
data Tree label = Branch (LabeledTree label) (LabeledTree label) | Leaf
no mutual recursion:
module A where
data LabeledTreeGen tree label = LabeledTree label (tree label)
module B where
type LabeledTree label = LabeledTreeGen Tree label
data Tree label = Branch (LabeledTree label) (LabeledTree label) | Leaf
More information about the Haskell-Cafe
mailing list