feb3 - power2 :: Integer -> Integer power2 n | n...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
x = 10 y = 12 simple :: Int -> Int simple x = x + y extra :: Int -> Bool extra y = x > y maxSq :: Int -> Int -> Int maxSq x y | sq x > sq y = sq x | otherwise = sq y where sq :: Int -> Int sq w = w * w fact :: Integer -> Integer fact n | n == 0 = 1 -- base step | n > 0 = n * fact (n-1) -- recursive step | otherwise = error "fact: negative input not allowed" -- power2 n computes 2^n
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: power2 :: Integer -> Integer power2 n | n == 0 = 1 | n > 0 = 2 * power2 (n-1) | otherwise = error "power2: negative input not allowed"-- fib n returns the nth Fibonacci number fib :: Integer -> Integer fib 0 = 0 fib 1 = 1 fib n | n > 1 = fib (n-1) + fib (n-2) | otherwise = error "fib: negative input not allowed"...
View Full Document

Ask a homework question - tutors are online