tricu

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

d52075fd243ce733529740023181faa44c7c3022a9f28ee7ea2aaa078d95f7b2.tri (619B)


      1 !import io_v2 as IO
      2 !import io_v2_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)