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.

- 163 -is a tuple consisting of two integers and a string. For example:- (("<strong>An</strong>na","Able"),"Accounts",101);> (("<strong>An</strong>na","Able"),"Accounts",101) : (string * string) * string * intis a tuple consisting of a tuple consisting of two strings, a string and an integer.These may be used <strong>to</strong> build tuple lists, for example a s<strong>to</strong>ck control list:- [("VDUs",250,120),("mice",155,170),("printers",43,20)];> [("VDUs",250,120),("mice",155,170),("printers",43,20)] : (string * int * int) lis<strong>to</strong>r a telephone direc<strong>to</strong>ry:- [(("<strong>An</strong>na","Able"),"Accounts",101),(("Betty","Baker"),"Boiler room",102),(("Cloe","Charlie"),"Cus<strong>to</strong>mer orders",103)];> [(("<strong>An</strong>na","Able"],"Accounts",101),(("Betty","Baker"),"Boiler room",102),(("Cloe","Charlie"),"Cus<strong>to</strong>mer orders",103)] : ((string * string) *string * int) listNote that if a tuple is defined with expression elements then those expressions are evaluated from left <strong>to</strong> right. Thus, astuples are used <strong>to</strong> specify bound variables for uncurried functions, such functions have a defined actual parameterevaluation order.9.6. Function types and expressionsA function uses values in an argument domain <strong>to</strong> produce a final value in a result range. In SML, a function’s type ischaracterised by its domain and range types:fn : -> Note the use of -> <strong>to</strong> indicate a function’s domain/range mapping.Tuples are normally used <strong>to</strong> enable uncurried functions with multiple bound variables.In SML, as in λ calculus and LISP, expressions are usually based on prefix notation function applications with thefunction preceding the arguments: Function applications are evaluated in applicative order.Note that function applications need not be explicitly bracketed but brackets should be used round arguments <strong>to</strong> avoidambiguity.SML enables uncurried binary functions <strong>to</strong> be used as infix opera<strong>to</strong>rs so the function name may appear in between thetwo arguments. They are then typed as if they had tuples for arguments. We won’t consider this further here.Similarly, many standard binary functions are provided as infix opera<strong>to</strong>rs. They may be treated as prefix functions ontuples by preceding them with:

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

Saved successfully!

Ooh no, something went wrong!