import Prelude hiding (map,foldr,sum,prod,curry,uncurry,(.),filter)
map :: (a -> b) -> [a] -> [b]
map f [] = []
map f (x:xs) = f x : map f xs
square :: Int -> Int
square x = x * x
isPos :: Int -> Bool
isPos x = x >= 0
inc :: Int -> Int
inc x = x + 1
-- Listen "falten":
foldr f e [] = e
foldr f e (x:xs) = f x (foldr f e xs)
sum = foldr (+) 0
prod = foldr (*) 1
fac n = prod [1 .. n]
-- "Currry"fizieren:
curry :: ((a,b) -> c) -> a -> b -> c
curry f x y = f (x,y)
uncurry :: (a -> b -> c) -> (a,b) -> c
uncurry f (x,y) = f x y
pairsum :: [(Int,Int)] -> Int
pairsum = sum . map (uncurry (+))
(.) :: (a -> b) -> (c -> a) -> (c -> b)
(f . g) x = f (g x)
filter :: (a -> Bool) -> [a] -> [a]
filter p [] = []
filter p (x:xs) | p x = x : filter p xs
| otherwise = filter p xs
-- Vielfachen aus einer Liste entfernen
rmdups :: Eq a => [a] -> [a]
rmdups [] = []
rmdups (x:xs) = x : rmdups (filter (/=x) xs)
qsort :: [Int] -> [Int]
qsort [] = []
qsort (x:xs) = qsort (filter (=x) xs)