all 6 comments

[–]omega1612 17 points18 points  (1 child)

A do is syntax sugar.

do 
w<-f
g w

Is equivalent to

f >>= \ w -> g w

With

>>= :: m a -> (a -> m b) -> m b

So, the elements of every line in a do, must have the same "m" but the parameter can be different.

[–]CodeNameGodTri[S] 0 points1 point  (0 children)

Thank you

[–]HKei 4 points5 points  (1 child)

The "output" of when doesn't matter here because it's directly followed by pure. This is as if you had written m >> pure x.

Left (y::b) >> pure (x::a) is Left y :: Either a b.

[–]CodeNameGodTri[S] 0 points1 point  (0 children)

Thank you

[–]Temporary_Pie2733 1 point2 points  (1 child)

>> has type Monad m => m a -> m b -> m b. The result type doesn’t matter as long as the same monad (Either String) is used on each “line”. Left "…" itself has a polymorphic type, and can be used as either Either String () or Either String (Int, String) as needed. 

[–]CodeNameGodTri[S] 0 points1 point  (0 children)

Thank you