What are Monads?

from my notes :slight_smile:

Monad

Functor -> Applicative -> Monad

class Applicative m => Monad m where
	(>>=) :: m a -> (a -> m b) -> m b
	(>>) :: m a -> m b -> m b
	return :: a -> m a

ok so to find what Monad is you need to know what Applicative is

Applicative

Functor -> Applicative

class Functor f => Applicative f where
	pure :: a -> f a
	(<*>) :: f (a -> b) -> f a -> f b
Prelude> (,) <$> [1, 2] <*> [3, 4]
[(1,3),(1,4),(2,3),(2,4)]

ok so to find what Applicative is you need to know what Functor is

Functor

class Functor f where
	fmap :: (a -> b) -> f a -> f b

And we have Functors in Elixr … :slight_smile:
(for example for each element in the list transform list to some other list)

But I see someone better explained than me
https://shane.logsdon.io/writing/functors-applicatives-and-monads-in-elixir/

3 Likes