[Haskell-cafe] mutually recursive types
Brent Yorgey
byorgey at gmail.com
Wed Aug 8 11:30:20 EDT 2007
> Notice that Scenario depends on a list of steps and Step has a dependence
> with scenario. I know that this is a kind of "bad smell".... in Haskell, are
> there any pattern or language idiom to deal with cyclical dependences?
Just a little something to add, this is not a "bad smell" at all... in fact,
recursive (including mutually recursive) data types are the bread and butter
of Haskell (and functional languages in general). For example:
data BinTree a = Empty | Branch a (BinTree a) (BinTree a)
This says that a binary tree containing 'a's is either Empty, or a Branch
consisting of an 'a' and two binary trees. This isn't stinky, it's quite
elegant. Your Scenario and Step data types look just peachy from an
idiomatic point of view; the solution (as others have pointed out) is to use
data declarations rather than type synonyms.
-Brent
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20070808/bfb8b3fa/attachment.htm
More information about the Haskell-Cafe
mailing list