-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbools.hs
42 lines (31 loc) · 930 Bytes
/
bools.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
myOr :: [Bool] -> Bool
myOr [] = False
myOr (x:xs) = if (x == True)
then True else (myOr xs)
myOr' :: [Bool] -> Bool
myOr' [] = False
myOr' xs = foldr (||) False xs
-- myOr' = foldr (||) False
myAny :: (a -> Bool) -> [a] -> Bool
myAny f [] = False
myAny f (x:xs) = if (f x == True)
then True else (myAny f xs)
myAny' :: (a -> Bool) -> [a] -> Bool
myAny' f [] = False
myAny' f xs = foldr (\x -> \y -> ) False xs
newtype Any a = Any { getAny :: Bool } deriving Show
newtype All a = All { getAll :: Bool } deriving Show
-- class Monoid a where
-- mempty :: a
-- mappend :: a -> a -> a
instance Monoid (Any a) where
mempty = Any False
mappend (Any a) (Any b) = Any (a || b)
instance Monoid (All a) where
mempty = All True
mappend (All a) (All b) = All (a && b)
data Days = Sunday | Monday deriving Show
data Either a b =
Left a
| Right b deriving Show
instance Functor (Either a) where