-
Notifications
You must be signed in to change notification settings - Fork 5
Notes for Week 13 Applicative Functors Part 2 Applicative Functors
learnhaskell-brisbane edited this page Feb 29, 2012
·
6 revisions
* What's the difference between Functors and Applicative Functors ?
* What's the difference between $ and <$> ?
Demonstrate using an IO action as an Applicative Functor.
Make the following Tree type an instance of Applicative:
data Tree a = Node (Tree a) (Tree a) | Leaf a deriving (Show, Eq)
Write a test that proves the following law:
pure f <*> x = fmap f x
Write calcTax, a function that takes 2 Maybes, the first Maybe contains an amount, the second contains a taxation function.
Return a Maybe with the result of applying the taxation function to the value.
testCalcTax = calcTax (Just 1000.00) (Just (/10)) == Just 100.00
Then write applyTax, same signatures as calcTax but returns the result of subtracting the taxation from the input amount.
testApplyTax = applyTax (Just 1000.00) (Just (/10)) == Just 900.00
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")
//TODO
//TODO
//TODO