I've been given the following piece of code, which I am trying to get my head around:
data MyExample e i = MyExample (CustomMonad e i)
| forall b. MyExample e b :>>= (b -> CustomMonad e b)
| forall b. (MyExample e (b -> a)) :<*> (MyExample e b)
| forall b. (b -> a) :<$> (MyExample e b)
1) What do :>>=
, :<*>
and :<$>
do differently, as opposed to
Monadic bind >>=
exampleFunction :: Int -> Maybe Int
exampleFunction el = Just (el + 100)
main = do
result <- exampleFunction >>= exampleFunction 21
Applicative combinators <*>
and <$>
exampleFunction :: Int -> Maybe Int
exampleFunction el = Just el
main = do
result <- pure exampleFunction <$> (+) <*> (ExampleType 2) <*> (ExampleType 4)
2) Am I right in saying the following:
a) MyExample (CustomMonad e i)
is constructing the CustomMonad
type with e and i, then wrapping this in the MyExample
context?
b) forall b. MyExample e b :>>= (b -> CustomMonad e b)
is taking a (MyExample e i)
then taking b and inputting this into a function (b -> CustomMonad e b
) that constructs a (CustomMonad e b)
?
c) forall b. (MyExample e (b -> a)) :<*> (MyExample eb)
is taking a MyExample
constructed with a value e
and a function (b -> a)
and perform some kind of applicative combinator operation with a MyExample e b
?
d) forall b. (b -> a) :<$> (MyExample e b)
is passing some result from (MyExample e b)
to a function (b -> a)
Additionally, am I right in saying the use of forall b
is ensuring that b
is the same type throughout the operation?