tricu

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

faeb5823b36c687703388225b7f221c90e47f7b0df59ea3d3e41b88c84d5869c.tri (613B)


      1 !import io as IO
      2 !import io_text as Text
      3 !export main
      4 !export run
      5 !export safeRead
      6 -- Ordinary read failures are application values; cleanup faults still fail the
      7 -- scope. Generic UTF-8 (including initial BOM), with an explicit 1-MiB budget.
      8 safeRead path = IO.bind (IO.scope (owner : do IO.onOk
      9   reader <- IO.openReader owner path
     10   Text.readText reader 1048576)) (reply : case reply of
     11     ((t t), (text, t)) = IO.pure text
     12     (t, (_, t)) = IO.pure "ERROR: Unable to read file"
     13     _ = IO.fail "Invalid file reply")
     14 main = IO.io (safeRead "demos/interactionTrees/greet.tri")
     15 run path = IO.io (safeRead path)