Functors

 Functors

Part 1 of the Functors, Monoids, and Monads presentation here: http://www.meetup.com/dynamic/events/222501291/

B3b78ba1acbf09ba202987d2d93ab72f?s=128

Kevin McCarthy

June 21, 2015
Tweet

Transcript

  1. 2.
  2. 12.

    fmap transforms a “normal” function (g :: a -> b)

    into one which operates over containers/contexts (fmap g :: f a -> f b). This transformation is often referred to as a lift; fmap “lifts” a function from the “normal world” into the “f world”.
  3. 13.

    *> :t add2 add2 :: Num a => a ->

    a *> :t crunch crunch :: Num a => a -> a *> :t fcrunch fcrunch :: (Functor f, Num b) => f b -> f b
  4. 14.

    instance Functor [] where fmap _ [] = [] fmap

    g (x:xs) = g x : fmap g xs -- or we could just say fmap = map
  5. 17.
  6. 18.

    –Wikipedia “In mathematics, a functor is a type of mapping

    between categories, which is applied in category theory. Functors can be thought of as homomorphisms between categories”
  7. 25.

    BROKEN FUNCTOR instance Functor [] where fmap _ [] =

    [] fmap g (x:xs) = g x : g x : fmap g xs