forked from carloseduardoweb/haskell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.hs
53 lines (34 loc) · 845 Bytes
/
test.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
double x = 2 * x
quadruple x = double (double x)
factorial n = product [1..n]
average ns = div (sum ns) (length ns)
a = b + c
where
b = 1
c = 2
n = a `div` length xs
where
a = 10
xs = [1,2,3,4,5]
last' xs = head (reverse xs)
last'' xs = xs !! ((-) (length xs) 1)
head' (x:_) = x
tail' (_:xs) = xs
init' xs = reverse(tail(reverse xs))
sum' :: Num t => [t] -> t
sum' xs = sum xs
palindrome xs = reverse xs == xs
twice :: (t -> t) -> t -> t
twice f x = f (f x)
twice' :: (t -> t -> t) -> t -> t -> t
twice' f x y = f (f x y) y
abs' :: (Num t, Ord t) => t -> t
abs' a = if a >= 0 then a else (-a)
signum' a = if a > 0 then '+' else
if a == 0 then ' ' else '-'
abs'' a | a > 0 = a
| a < 0 = (-a)
| otherwise = 0
and :: Bool -> Bool -> Bool
and True a = a
and False _ = False