ln015 - Higher-Order Programming From our discussions of...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Higher-Order Programming From our discussions of data types we know that types such as int int int * float bool char list int all describe sets of functions – but a data type is a set of data values . We can treat functions like data values that are members of a type. Example: - floor; val it = fn : real -> int - val x = floor; val x = fn : real -> int Chap 9
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Higher-Order Programming Def: In higher-order programming functions take functions as parameters or return functions as return values. Example : A generic type conversion function from real to int – this functions takes a real value and a specific type conversion function as arguments and converts the value according to the specific conversion function. - fun genconv (x:real, f:real -> int) = f(x); val genconv = fn : real * (real -> int) -> int Specific conversion functions: floor: real int ceil: real int round: real int - genconv(3.2, floor ); val it = 3 : int - genconv(3.2, ceil ); val it = 4 : int - genconv(3.2, round ); val it = 3 : int
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/03/2011 for the course CSC 301 taught by Professor Hamel during the Spring '08 term at Rhode Island.

Page1 / 7

ln015 - Higher-Order Programming From our discussions of...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online