High Order Functions

LA home
 FP,  λ
 Logic,  π

   High O.Fn

Also see:

The following high-order functions are well-known in functional programming and most FP libraries provide most of them, or equivalents.

fun curry   f x y  = f(x,y)
and uncurry f(x,y) = f x y

and map f   []    = []
  | map f (x::xs) = (f x)::(map f xs)

and foldl f z   []    = z
  | foldl f z (x::xs) = foldl f (f(z,x)) xs
(* BTW the opr, f, is curried in the Haskell version *)

and foldr f z   []    = z
  | foldr f z (x::xs) = f(z, (foldr f z xs))

val sum     = foldl (op +)  0
and product = foldl (op * ) 1;

(* ------------------------------------------tests-- *)
val l=[1,2,3,4];  sum l;  product l;

(* well known high order fns.    LA, CSSE, 22/6/2005 *)


  1. Which of the following are legal, and if so what is the type, or illegal, and if so why?
    curry curry
    curry uncurry
    uncurry curry
    uncurry uncurry
  2. Rewrite foldl and foldr so that parameter f is curried, and rewrite sum and product to match.
window on the wide world:

Computer Science Education Week

free op. sys.
free office suite,
ver 3.4+

~ free photoshop
web browser
like it says!

:: cons
[x1,...] list
[ ] list
@ append
fn =>  &lambda .
: has type

© L. Allison   http://www.allisons.org/ll/   (or as otherwise indicated),
Faculty of Information Technology (Clayton), Monash University, Australia 3800 (6/'05 was School of Computer Science and Software Engineering, Fac. Info. Tech., Monash University,
was Department of Computer Science, Fac. Comp. & Info. Tech., '89 was Department of Computer Science, Fac. Sci., '68-'71 was Department of Information Science, Fac. Sci.)
Created with "vi (Linux + Solaris)",  charset=iso-8859-1,  fetched Saturday, 27-Dec-2014 10:33:56 EST.