[Haskell-cafe] Mutual recursive data types
Luke Palmer
lrpalmer at gmail.com
Tue Apr 29 11:04:20 EDT 2008
On Tue, Apr 29, 2008 at 8:54 AM, rodrigo.bonifacio
<rodrigo.bonifacio at uol.com.br> wrote:
> Hi all,
>
> I have the following data types:
>
> type Id = String
> type Action = String
> type State = String
> type Response = String
>
> data Scenario = Scenario Description [Step]
> data Step = Step Id Scenario Action State Response
>
> So, there is a mutual recursion between Scenario and Step. Now, consider the following function:
>
> xmlScenario2Scenario :: XmlScenario -> Scenario
> xmlScenario2Scenario (XmlScenario description steps) =
> Scenario description [xmlStep2Step x | x <-steps]
>
> How can I send "scenario" as an argument for xmlStep2Step?
Like this:
let scenario = Scenario description [xmlStep2Step scenario x | x <- steps]
in scenario
> I've tried let and where but I get in a loop.
So it sounds like you already tried what I suggested. If you get in a
loop, then whatever you are doing is too strict to handle this kind of
self-reference. But it's hard to give suggestions without seeing more
of the code.
Luke
More information about the Haskell-Cafe
mailing list