haskell – Representing functions as trees

haskell – Representing functions as trees

Actually, the first expression is represented by Bush and the second by Tree.

In Haskell, g x y means that g x is applied to y; in C, g(x, y) means that g is applied to a collection of arguments — {x, y}. Therefore, in C:

f(g(x,y),z,h(t)) = Bush f [Bush g [Bush x [], Bush y []], Bush z [], Bush h [Bush t []]]

  f
  +--g
  |  +--x
  |  +--y
  |
  +--z
  |
  +--h
     +--t

And in Haskell:

f (g x y) z (h t) = App (App (App f (App (App g x) y)) z) (App h t)

         +
        / 
       /  /
      +  h  t  
     / 
    /  z
   f  +
     / 
    /  y
   g  x

haskell – Representing functions as trees

Leave a Reply

Your email address will not be published.