Flatmappable
Chainable
AndThenable
Computation builder
( I'll come back to this one )
( You can often apply them to many different instances )
Int -> Int
(+3)
add :: Int -> Int -> Int
add x y = x + y
add :: Int -> Int -> Int
add = (\x y -> x + y)
add :: Int -> (Int -> Int)
add x = (\y -> x + y)
three = 1 + 2
three = (+) 2 1
add1 = (+) 2
Missing a parameter?
show :: Int -> String
length :: String -> Int
digitCount :: Int -> Int
digitCount :: Int -> Int
digitCount value = length (show value)
digitCount :: Int -> Int
digitCount value = length . show value
digitCount :: Int -> Int
digitCount = length . show
(.) :: (b -> c) -> (a -> b) -> a -> c
data Suit = Club | Diamond | Spades | Diamond
data Rank = Two
| Three
| Four
| Five
| Six
| Seven
| Eight
| Nine
| Ten
| Jack
| Queen
| King
| Ace
data Card = Card Suit Rank
type Deck = [Card]
parseInt :: String -> Int
parseInt :: String -> Maybe Int
data Status = Verified | Unverified
data ShoppingCart = Empty | Active [Item] | Paid [Item]
Beautiful clean
internal model
Dirty unclean outside world
The Great Gate
(+1) :: Int -> Int
show :: Int -> String
( Increments a number by 1 )
( Returns the string representation of a number )
data Maybe a = Nothing | Just a
2 -- a value
Just 2 -- a value with context.
fmap (+3) (Just 2)
Just 5
class Functor f where
fmap :: (a -> b) -> f a -> f b
To make data type f a functor
You'll need to implement this function for your data type
map :: (a -> b) -> [a] -> [b]
map :: (Int -> String) -> [Int] -> [String]
map show [1, 2, 3, 4]
["1", "2", "3", "4"]
map (+1) [1, 2, 3, 4]
[2, 3, 4, 5]
(a -> b) -> ([a] -> [b])
(a -> b) -> (Maybe a -> Maybe b)
data Maybe a = Nothing | Just a