tricu

A lazy functional language based on Tree Calculus
Log | Files | Refs | README | LICENSE

shout.tri (636B)


      1 !import base as B
      2 !import io as IO
      3 !import io_text as Text
      4 !export main
      5 !export run
      6 !export shout
      7 safeRead path = IO.bind (IO.scope (owner : do IO.onOk
      8   reader <- IO.openReader owner path
      9   Text.readText reader 1048576)) (reply : case reply of
     10     ((t t), (text, t)) = IO.pure text
     11     (t, (_, t)) = IO.pure "missing"
     12     _ = IO.fail "Invalid file reply")
     13 shout path = IO.bind (safeRead path) (text : IO.pure (B.append text "!!!"))
     14 main = IO.io (IO.bind (shout "demos/interactionTrees/greet.tri") (text :
     15   IO.require IO.stdout (writer : IO.require (Text.writeText writer (B.append text "\n")) IO.pure)))
     16 run path = IO.io (shout path)