10.07.2015 Views

An Introduction to Functional Programming Through Lambda Calculus

An Introduction to Functional Programming Through Lambda Calculus

An Introduction to Functional Programming Through Lambda Calculus

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

- 98 -This leads naturally <strong>to</strong>:NIL = []which is a list of no objects with an implicit NIL at the end.For example, a list of pairs:CONS (CONS 5 (CONS 12 NIL))(CONS (CONS 10 (CONS 15 NIL))(CONS (CONS 15 (CONS 23 NIL))(CONS (CONS 20 (CONS 45 NIL))NIL)))becomes the compact:[[5,12],[10,15],[15,23],[20,45]]As before, HEAD selects the head element:HEAD (X::Y) = XHEAD [X,L] = XFor example:HEAD [[5,12],[10,15],[15,23],[20,45]] => ... =>[5,12]and TAIL selects the tail:TAIL (X::Y) = YTAIL [X,L] = [L]for example:and:TAIL [[5,12],[10,15],[15,23],[20,45]] => ... =>[[10,15],[15,23],[20,45]]TAIL [5] => ... =>[]Note that constructing a list with CONS is not the same as using [ and ]. For lists constructed with [ and ] there isan assumed empty list at the end. Thus:[,] ==CONS (CONS NIL)We may simplify long lists made from :: by dropping intervening brackets. Thus:::(::) ==::::

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!