Created
June 20, 2015 20:11
-
-
Save davidallsopp/4438ff9c9d7baf370ded to your computer and use it in GitHub Desktop.
Multi-line entry in GHCI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Monad.State | |
:{ | |
let test :: State Int Int | |
test = do | |
put 3 | |
modify (+1) | |
get | |
:} | |
print $ execState test 0 |
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
One-liners with
let
in ado
block are possible, but non-obvious - you have to wrap thelet
assignment in brackets: