environment.tri (578B)
1 !import prelude * 2 !import io * 3 !export * 4 5 -- Environment effects: ask and local. 6 -- ask reads the current environment value. 7 -- local f action runs action with the env transformed by f. 8 -- 9 -- The CLI starts with an empty (Leaf) environment. This demo uses 10 -- local to inject a real string so that ask returns something readable. 11 12 main = io <| 13 (bind 14 local (_ : "sandbox") 15 (bind ask (env : 16 bind (putStrLn (append "working in env: " env)) (_ : 17 pure "inside-done")))) 18 (outside : 19 bind (putStrLn (append "local returned: " outside)) (_ : 20 pure t))