Held: Monday, April 13, 1998
square x = x * x
is
Num t => t -> t
or "if type t is a numeric type then this a function from that type to that type.
type List t = Nil | Cons t (List t)
factorial :: Int -> Int factorial 0 = 1 factorial n = n * (fact (n-1))
Cons, car, and cdr.
car (Cons x xs) = x cdr (Cons x xs) = xs
Push, NewStack, top,
pop and empty.
data Stack a = NewStack | Push a (Stack a) pop :: Stack a -> Stack a pop (Push item stack) = stack pop NewStack = error top :: Stack a -> a top (Push item stack) = item top NewStack = error empty :: Stack a -> Bool empty NewStack = true empty (Push item stack) = false
if (I'm writing it as iif so that
we don't collide with the built-in version.)
iif :: Bool -> a -> a -> a iif True x y = x iif False x y = y
square (plus 2 3),
we might compute
square (plus 2 3) => times (plus 2 3) (plus 2 3) => times 5 (plus 2 3) => times 5 5 => 25
square (plus 2 3) => square 5 => times 5 5 25
fact n = iif (n == 0) 1 (n * (fact (n - 1)))
fact 1 => iif (1 == 0) 1 (1 * (fact (1 - 1))) => iif false 1 (n * (fact (1 - 1))) => iif false 1 (n * (fact 0)) => iif false 1 (iif (0 == 0) 1 (0 * (fact (0-1)))) => iif false 1 (iif false 1 (0 * (fact (0-1)))) => iif false 1 (iif false 1 (0 * (fact (-1)))) => iif false 1 (iif false 1 (0 * (iif (-1 == 0) 1 (-1 * fact(-1-1))))) => ...
Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.
Source text last modified Thu May 7 20:29:42 1998.
This page generated on Thu May 7 20:34:46 1998 by SiteWeaver.
Contact our webmaster at rebelsky@math.grin.edu