Given the example from the book:
User
<$> getParam "name" params
<*> getParam "email" paramsWalk through the steps of evaluation of this code, given the following cases
getParam "name" params returns |
getParam "email" params returns |
|---|---|
Nothing |
Nothing |
Just "Johnny" |
Just "[email protected]" |
Just "Johnny" |
Nothing |
Nothing |
Just "[email protected]" |
Try to do this without the book, using it to check yourself.
Given the following definition:
data DeciderOutcome a
= Outcome a
-- ^ We got an outcome (e.g. dice roll of 2, coin flip of heads)
| ErrorFlewOffTable
-- ^ Our decider didn't properly land on the table
| ErrorLandedOnItsEdge
-- ^ Our decider defied physics and landed on its edge/corner/sideWrite DeciderOutcome's Functor instance.
Write DeciderOutcome's Applicative instance.
Find the Applicative laws online.
Write DeciderOutcome's Monad instance.
Define unlawfull Functor, Applicative, and Monad instances that still compile.
Thought experiment: Pick Functor, Applicative or Monad: how many ways are there to define unlawful instances of DeciderOutcome that still compile?
Don't consider bottom (e.g. error, undefined, etc...) when thinking about this.
What insights about the laws do your unlawfull instances yield?
Write the 3 instances for this custom list type
data DescriptiveList a
| EmptyList
-- ^ The list is empty
| Cons a String (DescriptiveList a)
-- ^ "`Cons`truct" a list with
--
-- * An element, `a`
-- * A description of the element, `String`
-- * The rest of the list, `(DescriptiveList a)`
--You may use Haskell's built-in list ([]) instances for reference.