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.

- 238 -starts ((h1::t1):string list) ((h2::t2):string list) =if h1=h2then starts t1 t2else false;fun find1 [] (s2:string list) = 1 |find1 (s1:string list) [] = 1 |find1 (s1:string list) (s2:string list) =if starts s1 s2then 1else 1+(find1 s1 (tl s2));fun find (s1:string) (s2:string) =let val pos = find1 (explode s1) (explode s2)inif pos > (size s2)then 0else posend;5)fun east Queens_Street = Bishopbriggs |east Bishopbriggs = Lenzie |east Lenzie = Croy |east Croy = Polmont |east Polmont = Falkirk_High |east Falkirk_High = Linlithgow |east Linlithgow = Haymarket |east Haymarket = Waverly |east Waverly = Waverly;fun west Queens_Street = Queens_Street |west Bishopbriggs = Queens_Street |west Lenzie = Bishopbriggs |west Croy = Lenzie |west Polmont = Croy |west Falkirk_High = Polmont |west Linlithgow = Falkirk_High |west Haymarket = Linlithgow |west Waverly = Haymarket;6)fun eval (numb(i:int)) = i |eval (add(e1:exp,e2:exp)) = (eval e1)+(eval e2) |eval (diff(e1:exp,e2:exp)) = (eval e1)-(eval e2) |eval (mult(e1:exp,e2:exp)) = (eval e1)*(eval e2) |eval (quot(e1:exp,e2:exp)) = (eval e1) div (eval e2);Chapter 101)i) (defun nsum (n)(if (eq 0 n)

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

Saved successfully!

Ooh no, something went wrong!