I’m doing a past Function Programming exam paper and have this question:
Here are two ways of writing essentially the same expression:
f (g(x,y),z,h(t))
f (g x y) z (h t)
(a) Illustrate the different structures of the two expressions by drawing them as two different kinds of tree.
(b) Define Haskell data types Bush a and Tree a to capture the two different structures.
I’m kind of stuck because I’ve never done any thing like this in my course. It’s pretty obvious from a later part that the first expression should be represented by Tree a and the second by Bush a, but I don’t really know where to go from here. I guessed something like:
data Tree a = Leaf a | Node (Tree a) (Tree a)
data Bush a = Node a [Bush a]
But I don’t think the Binary tree type is the right one to use. Could someone point me in the right direction?
Actually, the first expression is represented by
Bushand the second byTree.In Haskell,
g x ymeans thatg xis applied toy; in C,g(x, y)means thatgis applied to a collection of arguments —{x, y}. Therefore, in C:And in Haskell: