[Haskell-beginners] Join'ing a State Monad, example from LYH

Olumide 50295 at web.de
Sat Feb 10 14:48:07 UTC 2018


Dear List,

I've been stumped for a few months on the following example, from 
chapter 13 of LYH
http://learnyouahaskell.com/for-a-few-monads-more#useful-monadic-functions

runState (join (State $ \s -> (push 10,1:2:s))) [0,0,0]

I find the following implementation of join in the text is hard to 
understand or apply

join :: (Monad m) => m (m a) -> m a
join mm = do
	m <- mm
	m

In contrast, I find the following definition(?) on Haskell Wikibooks
https://en.wikibooks.org/wiki/Haskell/Category_theory#Monads

join :: Monad m => m (m a) -> m a
join x = x >>= id

easier to understand, and although I can apply it to the following 
Writer Monad example, in the same section of LYH,

runWriter $ join (Writer (Writer (1,"aaa"),"bbb"))

I cannot apply it to the State Monad example.

Regards,

- Olumide


More information about the Beginners mailing list