Michael Trotter
Jane.com
slack.utahjavascript.com
#fun-ctional
haskellbook.com
mostly adequate guide (to fp)
learn you a haskell
ints :: [Int]
sumInts :: [Int] -> Intfloats :: [Float]
sumFloats :: [Float] -> Floatbools :: [Bool]
sumBools :: [Bool] -> BoolsuperInts :: [SuperInt]
sumSuperInts :: [SuperInt] -> SuperIntxs :: [a]
sumXs :: [a] -> adoStuff :: [a] -> a
doStuff = doAllTheThingsdoStuff :: [a] -> adoStuff = doAllTheThingsclass Functor f where
fmap :: (a -> b) -> f a -> f binstance Functor [] where
fmap = mapclass Monoid a where
mempty :: a
mappend :: a -> a -> a
mconcat :: [a] -> aclass Monoid a where
mempty :: a
mappend :: a -> a -> a
mconcat :: [a] -> aints :: [Int]
ints = [1, 2, 3]
sumInts :: [Int] -> Int
sumInts xs = mconcat xs
sumInts intsints :: [Int]
ints = [1, 2, 3]
sumInts :: [Int] -> Int
sumInts xs = mconcat xs
multiplyInts :: [Int] -> Int
multiplyInts xs = mconcat xs
sumInts ints
multiplyInts intsnewtype Sum = Sum Int
instance Monoid Sum where
mempty = Sum 0
mappend (Sum x) (Sum y) = Sum (x + y)
newtype Product = Product Int
instance Monoid Product where
mempty = Product 1
mappend (Product x) (Product y) = Product (x * y)ints :: [Int]
ints = [1, 2, 3, 4]
sumInts :: [Int] -> Int
sumInts xs = getInt (mconcat (map Sum xs))
multiplyInts :: [Int] -> Int
multiplyInts xs = getProduct (mconcat (map Product xs))
sumInts ints -- | 10
multiplyInts ints -- | 24class Functor f where
fmap :: (a -> b) -> f a -> f binstance Functor [] where
-- | :: (a -> b) -> [a] -> [b]
fmap fn xs = map fn xsinstance Functor [] where
fmap = mapints :: [Int]
ints = [1, 2, 3, 4]
sumInts :: [Int] -> Int
sumInts xs = getInt (mconcat (fmap Sum xs))
multiplyInts :: [Int] -> Int
multiplyInts xs = getProduct (mconcat (fmap Product xs))
sumInts ints -- | 10
multiplyInts ints -- | 24fmap (+1) [1, 2, 3, 4] -- | [2, 3, 4, 5]fmap (+1) (Just 1) -- | Just 2
fmap (+1) Nothing -- | Nothingdata Maybe a = Nothing | Just afmap (+1) [1] -- | [2]
fmap (+1) [] -- | []fmap (+1) (Just 1) -- | Just 2
fmap (+1) Nothing -- | Nothinginstance Functor (Maybe a) where
fmap fn (Just a) = Just (fn a)
fmap _ Nothing = Nothing
A data structure you can run a computation inside