Skip to content

Notes for Week 13 Applicative Functors Part 2 Applicative Functors

learnhaskell-brisbane edited this page Feb 27, 2012 · 6 revisions

Links:

Exercises:

Exercise 1

* What's the difference between Functors and Applicative Functors ?
* What's the difference between $ and <$> ?

Exercise 2

Demonstrate using an IO action as a Functor and as an Applicative Functor.

Exercise 3

Make the following Tree type an instance of Applicative:

     data Tree a = Node (Tree a) (Tree a)
        | Leaf a
          deriving Show

Prove that it follows the two Applicative laws.

Exercise 4

Write 3 Applicative alternative functions (concatPure, concatFmap, concatDollar) for the following function:

concat :: Maybe String -> Maybe String -> Maybe String
concat (Just x) (Just y) = Just (x ++ y)

Test functions:
---------------
testConcatPure   = concatPure (Just "Yes") (Just "No") == (Just "YesNo")
testConcatFmap   = concatFmap (Just "Yes") (Just "No") == (Just "YesNo")
testConcatDollar = concatDollar (Just "Yes") (Just "No") == (Just "YesNo")

Questions raised during the group:

//TODO

Answers to Exercises:

//TODO

Interesting Asides

//TODO
Clone this wiki locally