@@ -471,23 +471,60 @@ Just 3
471471Nothing
472472```
473473
474+ ---
475+
476+ # ` Applicative `
477+
478+ <!-- exdown-skip -->
479+ ``` hs
480+ class Functor f => Applicative f where
481+ pure :: a -> f a
482+
483+ (<*>) :: f (a -> b ) -> f a -> f b
484+
485+ -- Inherited from @Functor f@ constraint
486+ (<$>) :: Functor f => (a -> b ) -> f a -> f b
487+ ```
488+
474489--
475490
491+ Combining `<*> ` and `<$> ` lifts `pure` under the hood:
492+
493+
476494```bash
477- > (+) < $> Nothing < * > Just 2
478- Nothing
495+ > pure (+) <*> Just 1 <*> Just 2
496+ Just 3
497+ > (+) <$> Just 1 <*> Just 2
498+ Just 3
499+ ```
500+
501+ ---
502+
503+ # ` Applicative `
504+
505+ <!-- exdown-skip -->
506+ ``` hs
507+ class Functor f => Applicative f where
508+ pure :: a -> f a
509+
510+ (<*>) :: f (a -> b ) -> f a -> f b
511+
512+ -- Inherited from @Functor f@ constraint
513+ (<$>) :: Functor f => (a -> b ) -> f a -> f b
479514```
480515
481- * TODO next year: this didn't flow really well.
482- * Use https://youtu.be/8oVHISjS3wI?t=311 as inspiration
516+ Tying it all together, we have container- agnostic transformations:
483517
484518<!-- exdown- skip -->
485519```hs
486520> : type (++)
487521String -> String -> String
488- > (++) <$> Just " John" <*> Just " Travolta"
489- > : type ((++) <$> Just " John" )
522+ > : type ((++) <$> Just " Philippe" )
490523Maybe (String -> String )
524+ > (++) <$> Just " Philippe" <*> Just " Katerine"
525+ Just " Philippe Katerine"
526+ > (++) <$> [" Philippe" ] <*> [" Katerine" ]
527+ [" Philippe Katerine" ]
491528```
492529
493530---
@@ -517,6 +554,7 @@ How to compose functions:
517554- https://learnyouahaskell.github.io/syntax-in-functions.html
518555- https://learnyouahaskell.github.io/higher-order-functions.html
519556- https://youtu.be/8oVHISjS3wI
557+ - [ Graham Hutton] ( https://youtu.be/8oVHISjS3wI?t=311 ) 's course on applicative functors
520558
521559---
522560
0 commit comments