Skip to content

Instantly share code, notes, and snippets.

@WillNess
Last active December 16, 2015 20:10
Show Gist options
  • Select an option

  • Save WillNess/5490745 to your computer and use it in GitHub Desktop.

Select an option

Save WillNess/5490745 to your computer and use it in GitHub Desktop.
a note on dave4420's comment:
sequence [a,b]
= a >>= (\x -> b >>= (\y -> return [x,y]))
= a >>= (\x -> sequence [b] >>= (\xs -> return x:xs))
For `Monad ((->) r)`, `(f >>= k) r = k (f r) r = (k.f) r r = join (k.f) r`
(makes sense, because in general, `f>>=k = join (fmap k f)`.
so, `sequence [a,b] r = (a >>= k1) r = k1 (a r) r`.
(`a :: m x ~ (r -> x)`, `k1 :: (x -> m [x]) ~ (x -> r -> [x])`,
`a>>=k1 :: m [x]`).
so, `sequence :: [m a] -> m [a] ~ [r -> a] -> (r -> [a])`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment