Skip to content

Instantly share code, notes, and snippets.

@dcastro
Created September 27, 2017 11:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcastro/9a2d2596d484865e0f1fec335e2a88fe to your computer and use it in GitHub Desktop.
Save dcastro/9a2d2596d484865e0f1fec335e2a88fe to your computer and use it in GitHub Desktop.
Expanding `>>=` on functions
-- start with
(+) >>= id $ 2
-- Expand `>>=` using the Monad instance for functions
-- instance Monad ((->) r) where
-- f >>= k = \ r -> k (f r) r
(\r -> id ((+) r) r) $ 2
-- beta reduction
id ((+) 2) 2
-- expand `id`
((+) 2) 2
2 + 2
4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment