I have the following block of code:
data G = F G G | H Int deriving (Show, Eq)example :: Int -> G -> Gexample 0 (H i) = (H i)example n (H i) = F (example (n-1) (H i)) (example (n-1) (H i))example n (F i1 i2) = F (example n i1) (example n i2)
When I run example 0 (F (H 1) (H 2))
, as expected it returns F (H 1) (H 2)
When I run example 1 (F (H 1) (H 2))
, it returns F (F (H 1) (H 1)) (F (H 2) (H 2))
This is not what I want. I need to return F (F (H 1) (H 1)) (H 2)
What I mean is on the 6th line, example n (F i1 i2) = F (example n i1) (example n i2)
, I call the recursive function twice. However I wish for (example n i1)
to evaluate first and update the variable n
before we evaluate (example n i2)
Any help/solutions to this exact problem will be greatly appreciated. I have been trying for hours with zero success.