More example if you wish.
With some more operators.
Explaining Monad
This tutorial/ guidance/ article is one of some parts.

Overview: Summary.

References: About Monad.

Examining Bind: Bind
>>=
operator. Hello World Example. 
Examining Bind:
<*>
and<$>
operators. Personal Notes. Example using Number. 
Monadic Operator: Fish
>=>
operator.
The first one is overview, then some references. The last three parts is all about Example Code.
How does Monad works
I found good explanation about these three magic words (functor, applicative, and monad), using boxing analogy. I really respect the reader on how he made everything clear by putting some funny image on his article.
There’s a caveat in boxing analogy.
I did this note based on adit
works.
But since, it has some differences, with some additional notes also.
I decide to make my own article.
Context: Maybe, Just and Nothing
Haskell has context that can be wrapped around data type.
Maybe
, Just
and Nothing
.
This context approach solved common null value issue.
Now a data Maybe contain Nothing or Just a value.
Consider open GHCI
and do some Math.
Compare with plain data above, now we can wrap data in a context.
Just
is just a wrapper. Do not forget the bracket.
Bare unwrapped
Consider this Prelude using application operator and its reverse.
Function is left associative. Apply left bare function to the bare value right.
Functor
How do we suppose to do simple thing with data context?
Here comes the <$>
operator in rescue.
<$>
is left associative.
Apply left bare function to the wrapped context right.
Lists are functors.
We can rewrite it using fmap
alias,
or special map
for list.
fmap
is a generalisation of map
.
map
is a specialization of fmap
.
Function are Functor too. It looks like magic, but it is not.
Applicative
How about also wrapping the left function ?
Here comes the <*>
operator.
<*>
is also left associative.
Apply left wrapped function to the context right.
Using List
Wrapping, in Functor and Applicative
Using boxing analogy.
While <$>
wrapped the value.
The <*>
also wrapped the function.
In context
Go further with both.
Bind
Apply it to bind.
And chain ‘em.
Rewrite the last sentence in multiline GHCI.
And finally in do
block.
Operator Cheat Sheet
Bear in mind

$
function application 
.
function composition 
<$>
fmap
as an infix operator.`fmap`
. 
<*>
Applicative 
(<$>) :: Functor f => (a > b) > f a > f b

(<$>) = fmap

fmap :: Functor f => (a > b) > f a > f b

map :: (a > b) > [a] > [b]

(<*>) :: f (a > b) > f a > f b
Bear in mind.
More in this blog.
Further Explanation.
Meanwhile. Consider go back to adit
Thank you for Reading.
AttributionShareAlike 4.0 International (CC BYSA 4.0)
Archives
 December 2017
 August 2017
 July 2017
 June 2017

May 2017
 Examining Bind in Haskell: Do Notation
 Examining Bind in Haskell: Hello World
 Explaining Monad: References
 Explaining Monad: Overview
 Loop in Haskell With Map, Part Three
 Loop in Haskell With Map, Part Two
 Loop in Haskell With Map, Part One
 Loop in Haskell With Map, Overview
 Modularized HerbstluftWM in Haskell
 Modularized HerbstluftWM in Lua
 Modularized HerbstluftWM in PHP
 Modularized HerbstluftWM in Ruby
 Modularized HerbstluftWM in Python
 Modularized HerbstluftWM in Perl
 Modularized HerbstluftWM in BASH
 Modularized HerbstluftWM Overview
 April 2017