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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

- 169 -Functions have the form:fn => A bound variable is known as an alphabetic identifier and consists of one or more letters, digits and _s starting with aletter, for example:oxymoron Home_on_the_range Highway61A function’s bound variable may be a single bound variable or a tuple of bound variable elements.For example:- fn x => x+1;> fn : int -> intincrements its argument.Note that SML deduces that the domain and range are int because + is used with the int argument 1.For example:- fn x => fn y => not (x orelse y);> fn : bool -> (bool -> bool)is the boolean implication function.Note that orelse has a boolean tuple domain so x and y must both be boolean. Similarly, not returns a boolean sothe inner function:has type:fn y => not (x orelse y)bool -> boolHence, the whole function has type:fn : bool -> (bool -> bool)This might have been written with a tuple domain:- fn (x,y) => not (x orelse y);> fn : (bool * bool) -> bool9.14. Making bound variables’ types explicitSuppose we try <strong>to</strong> define a squaring function:fn x => x*xBecause * is overloaded, SML cannot deduce x’s type and will reject this function.Domain types may be made explicit by following each bound variable with its type. Thus for a single bound variable:( : )

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

Saved successfully!

Ooh no, something went wrong!