Part 3
let count = 1
let add x y = x + y
let v = 2 :: Int
let h = 3 :: Floatadd 1 2
let add10 = add 10[x*2 | x <- [1..10], x*2 >= 12] [ x*y | x <- [2,5,10], y <- [8,10,11]] [x*2 | x <- [1..10]] fst, snd, zip
(+1) :: Int -> Int(+) :: Int -> Int -> Int:t (==)(==) :: (Eq a) => a -> a -> Bool Everything before => is called a class constraint
The (==) function takes two values of the same type and returns a Bool.
The type of the two types must be a member of the the Eq typeclass,
elem :: (Eq a) => a -> [a] -> Booldata Day = Mon | Tue | Wed | Thu | Fri | Sat | Sun
deriving (Eq)Mon == FriFri /= Wed(<) :: (Ord a) => a -> a -> Bool :t (<)data Day = Mon | Tue | Wed | Thu | Fri | Sat | Sun
deriving (Eq, Ord)Mon > FriFri > Weddata Day = Mon | Tue | Wed | Thu | Fri | Sat | Sun
deriving (Enum)[Mon..Fri]succ Fripred Fridata Day = Mon | Tue | Wed | Thu | Fri | Sat | Sun
deriving (Show)show Fridata Day = Mon | Tue | Wed | Thu | Fri | Sat | Sun
deriving (Read)read "Fri"13 :: (Num t) => t :t 13:t 13 :: Int:t 13 :: Float:t 13 :: Double:t (+)(+) :: (Num a) => a -> a -> a (1 :: Double) + (3 :: Int)is just another typeclass
data Maybe a = Nothing | Just a2 -- a normal value
Just 2 -- a type of context wrapping a value
Nothing -- an empty type of contextNothing :: Maybe a
Just :: a -> Maybe a
> fmap (+3) (Just 2)
Just 5> fmap (+3) Nothing
Nothingclass Functor f where
fmap :: (a -> b) -> f a -> f bTo make datatype f a functor
You'll need to implement this function for your data type
isOne :: Int -> Bool
isOne 1 = True
isOne _ = Falsepow :: Int -> Int -> Int
pow _ 0 = 1
pow a b = a^binstance Functor Maybe where
fmap function (Just x) = Just (function x)
fmap function Nothing = Nothing fmap (+3) (Just 2)fmap (+3) Nothingfmap (+3) [2,4,6]instance Functor [] where
fmap = mapThat's all folks