pascalabcnet/TestSamples/Haskell_Samples/PreduleModule.hs
Бондарев Иван e6e67c193c initial commit
2015-05-14 21:35:07 +02:00

50 lines
936 B
Haskell

module PreduleModule where
eq x y = x==y
noteq x y = not(x==y)
max x y | x <= y = y
max x y | x > y = x
min x y | x <= y = x
min x y | x > y = y
succ x = x+1
pred x = x-1
condition x = x>4
until p f x | p(x) = x
until p f x | otherwise = until(p f f(x))
map f [] = []
map f x:xs = f(x) : map(f xs)
filter p [] = []
filter p x:xs | p(x) = x : filter(p xs)
filter p x:xs | otherwise = filter(p xs)
head [] = "Prelude.head: ïóñòîé ñïèñîê"
head x:xs = x
tail [] = "Prelude.tail: ïóñòîé ñïèñîê"
tail x:xs = xs
length [] = 0
length h:t = length (t) + 1
init [] = "Prelude.init: ïóñòîé ñïèñîê"
init x | length(x)==1 = []
init x | otherwise = head(x) : init(tail(x))
f x y = x+y
foldr a x [] = x
foldr a x h:t = a(h foldr(a x t))
foldl a z [] = z
foldl a z x:xs = foldl(a a(z x) xs)