Skip to content

Instantly share code, notes, and snippets.

@davidallsopp
Created June 20, 2015 20:11
Show Gist options
  • Save davidallsopp/4438ff9c9d7baf370ded to your computer and use it in GitHub Desktop.
Save davidallsopp/4438ff9c9d7baf370ded to your computer and use it in GitHub Desktop.
Multi-line entry in GHCI
import Control.Monad.State
:{
let test :: State Int Int
test = do
put 3
modify (+1)
get
:}
print $ execState test 0
@davidallsopp
Copy link
Author

Another do-block example, with equivalent >>=

Prelude> [1,2,3] >>= \x -> [x,x] >>= \x -> [x+1]
[2,2,3,3,4,4]

Prelude> :{
Prelude| do
Prelude|   x <- [1,2,3]
Prelude|   [x,x]
Prelude| :}

[1,1,2,2,3,3]

Prelude> :{
Prelude| do
Prelude|   x <- [1,2,3]
Prelude|   y <- [x,x]
Prelude|   [y+1] -- or return (y+1)
Prelude| :}

[2,2,3,3,4,4]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment