state.tri (550B)
1 !import prelude * 2 !import io * 3 !export * 4 5 -- Mutable state via get and put. 6 -- get reads the current state. 7 -- put replaces the state. 8 -- 9 -- The CLI starts with an empty (Leaf) state. This demo puts 10 -- readable strings and prints them back out. 11 12 main = io <| 13 bind (put "idle") (_ : 14 bind get (s1 : 15 bind (putStrLn (append "state: " s1)) (_ : 16 bind (put "running") (_ : 17 bind get (s2 : 18 bind (putStrLn (append "state: " s2)) (_ : 19 bind (put "done") (_ : 20 bind get (s3 : 21 bind (putStrLn (append "state: " s3)) (_ : 22 pure t)))))))))