Created
October 3, 2014 18:03
-
-
Save lmarburger/5a93e855effd70891b91 to your computer and use it in GitHub Desktop.
Playing with state effects in Idris
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
$ idris state.idr -p effects | |
____ __ _ | |
/ _/___/ /____(_)____ | |
/ // __ / ___/ / ___/ Version 0.9.14.3 | |
_/ // /_/ / / / (__ ) http://www.idris-lang.org/ | |
/___/\__,_/_/ /_/____/ Type :? for help | |
Idris is free software with ABSOLUTELY NO WARRANTY. | |
For details type :warranty. | |
*state> testAdd 1 | |
12 : Nat |
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 Effect.State | |
addFive : { [STATE Nat] } Eff (Nat) | |
addFive = do i <- get | |
put (i + 5) | |
pure 42 -- Communicate using shared state. Return a meaningless value. | |
addSix : { [STATE Nat] } Eff (Nat) | |
addSix = do i <- get | |
put (i + 6) | |
pure 24 -- Communicate using shared state. Return a meaningless value. | |
testAdd : Nat -> Nat | |
testAdd n = runPure (do put n | |
addFive | |
addSix | |
n' <- get | |
pure n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment