Skip to content

Notes for Week 12 Applicative Functors Part 1 Functors and Functor Laws

newmana edited this page Feb 28, 2012 · 18 revisions

Links:

Exercises:

Exercise 1

* What are Functors useful for?
* What's the difference between fmap and (.) ?  Explain.

Exercise 2

Demonstrate using an IO action as a Functor.

Exercise 3

Make the following Tree type an instance of Functor:

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

Use the following test to get it working (returns true):

     testFmap = (fmap (+1000) $ Node (Leaf 100) (Leaf 200)) == (Node (Leaf 1100) (Leaf 1200))

Prove that it follows the two Functor laws by writing the following tests:

     --testIdLaw = 
     --testComposeLaw = 

Links

Questions raised during the group:

Answers to Exercises:

//TODO

Interesting Asides

//TODO

Clone this wiki locally