[Haskell-cafe] n00b circular dep question

Jennifer Miller ogina at mac.com
Fri Apr 25 23:50:51 EDT 2008


Thanks for the suggestions. The #include worked but I will look for ways to remove the circular dependency altogether.

Jennifer


 
On Friday, April 25, 2008, at 02:48PM, "Henning Thielemann" <lemming at henning-thielemann.de> wrote:
>
>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