Skip to content

Instantly share code, notes, and snippets.

@lmarburger
Created October 3, 2014 18:03
Show Gist options
  • Save lmarburger/5a93e855effd70891b91 to your computer and use it in GitHub Desktop.
Save lmarburger/5a93e855effd70891b91 to your computer and use it in GitHub Desktop.
Playing with state effects in Idris
$ 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
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