applyAll :: [(a -> a)] -> a -> a

applyAll = flip (foldr aux)

where aux f x = f x

power f n = foldr (.) id (replicate n f)

]]>polygon :: [Coordinate] -> Region

polygon x

| (length x) < 3 = error "polygon: requires at least 3 points"

| otherwise = halfPlane (head x) (tail x ++ [head x])

where halfPlane x1 (x2:xs) = HalfPlane x1 x2 `Intersect` halfPlane x2 xs

halfPlane _ [] = Complement Empty

Using this kind of definition, it runs indefinitely (or until out of memory error) when actually evaluated. For example,

fiveCircles’ `containsR` (0, 0)

I can think of the above short-coming but I don’t know the “trade-offs” the exercise asked about.

]]>takeTree 0 _ = ILeaf

takeTree _ ILeaf = ILeaf

takeTree n (IBranch x t1 t2) = IBranch x (takeTree (n-1) t1) (takeTree (n-1) t2)

takeTreeWhile _ ILeaf = ILeaf

takeTreeWhile pred (IBranch x t1 t2)

| pred x = IBranch x (takeTreeWhile pred t1)

(takeTreeWhile pred t2)

| otherwise = ILeaf

Also, guard can be used instead of if expression in takeTreeWhile.

]]>

makeChange amt cs = zipWith div modList cs

where modList = amt : map (mod amt) cs

Without currying:

makeChange amt cs = zipWith div modList cs

where modList = amt : map doMod cs

doMod x = amt `mod` x

]]>sequence (map (*) [1..4]) 5

]]>