double x = x + x
quad x = double (double x)
fact1 1 = 1
fact1 n = n * fact1 (n-1)
fact2 n = product [1..n]
power n 0 = 1
power n k = n * power n (k-1)
not' False = True
not' True = False
and' True True = True
and' _ _ = False
and2 True b = b
and2 False _ = False
head' (x:_) = x
tail' (_:xs) = xs
len [] = 0
len (_:xs) = 1 + len xs
last' (x:[]) = x
last' (_:xs) = last' xs
first (x,_) = x
second (_,x) = x
dist1 (x1,y1) (x2,y2) =
let
dx = (x1-x2)
dy = (y1-y2)
in sqrt (dx^2 + dy^2)
dist2 (x1,y1) (x2,y2) = sqrt (dx^2 + dy^2)
where
dx = x1 - x2
dy = y1 - y2
sgn n | n < 0 = -1
| n == 0 = 0
| otherwise = 1
flat1 xss = [x | xs <- xss, x <- xs]
factors n = [x | x <- [1..n], mod n x == 0]
prime n = factors n == [1,n]
primes = [ x | x <- [2..], prime x]
qsort [] = []
qsort (x:xs) = qsort [ a | a <- xs, a < x]
++ [x] ++
qsort [ a | a <- xs, a >= x]
qsort2 [] = []
qsort2 (x:xs) = qsort2 smaller ++ [x] ++ qsort2 larger
where smaller = [ a | a <- xs, a < x]
larger = [ a | a <- xs, a >= x]