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.

- 184 -- val identity = fn x => x;> val identity = fn : ’a -> ’a- identity identity;> fn : ’a -> ’a- val apply = fn f => fn x => (f x);> val apply = fn : (’a -> ’b) -> (’a -> ’b)- apply identity identity;> fn : ’a -> ’aas applicative order evaluation replaces name arguments with values.Some of our λ functions cannot be represented directly in SML as the type system won’t allow self application. Forexample, in:fn s => (s s)there is a type inconsistency in the function body:(s s)Here, the s in the function position is untyped so it might be ’a -> ’b. Thus, the s in the argument position shouldbe ’a but this clashes with the type for the s in the function position!9.26. Other featuresThere are many aspects of SML which we cannot cover here. Most important are abstract type construction andmodularisation techniques and the use of exceptions <strong>to</strong> change control flow, in particular <strong>to</strong> trap errors. SML alsoprovides imperative constructs for assignment, I/O and iteration.9.27. SummaryIn this chapter we have:• surveyed quickly Standard ML(SML)• seen how <strong>to</strong> implement algorithms from preceding chapters in SML• seen that some pure λ functions cannot be represented in SML9.28. Exercises1) Write and test functions <strong>to</strong>:i) Find y 3 given integer y.ii)Find x implies y from x implies y == not x or y given x and y. The function impliesshould be prefix.iii) Find the smallest of the integers a, b and c.

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

Saved successfully!

Ooh no, something went wrong!