Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recover the do notation syntax

Tags:

I was reading through Scrap your type classes. This provides an alternatives for type classes. However, I was stuck with a comment by Paul Chiusano which talked about recovering the do notation syntax.

Frankly I could not understand how

return :: a -> (Monad f -> f a) 
(>>=) :: (Monad f -> f a) -> (a -> (Monad f -> f b)) -> (Monad f -> f b)

would help recover do notation

You can implement all the monadic combinators like this, and desugar do notation to them. The do block evaluates to a function that accepts the monad dictionary, so you can even conveniently write code that's polymorphic in the choice of monad, without having to thread the dictionary around manually.

And especially, how it would fit int he context of GADT style approach mentioned in the above article?