tricu

An interpreted language for exploring Tree Calculus
Log | Files | Refs | README | LICENSE

state.tri (559B)


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