tricu

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

65c006672139d98c27b5022a8641c73b6d0c9c29dd42f6cfe8b4820928664807.tri (928B)


      1 !import base as B
      2 !import io_v2 as IO
      3 !import io_v2_text as Text
      4 !export main
      5 !export run
      6 !export writeThenRead
      7 -- Check write/close success before opening a reader; do not discard the write
      8 -- Result. Select the output path explicitly, rather than clobbering shared /tmp.
      9 writeThenRead path text = IO.scope (owner : do IO.onOk
     10   writer <- IO.openWriter owner path
     11   Text.writeText writer text
     12   IO.close writer
     13   reader <- IO.openReader owner path
     14   Text.readText reader 1048576)
     15 main = IO.io (IO.require (IO.environmentVariable "TRICU_DEMO_OUTPUT") (selection : case selection of
     16   ["value" path] = IO.require (writeThenRead path "hello from tricu") (text :
     17     IO.require IO.stdout (writer : IO.require (Text.writeText writer (B.append text "\n")) IO.pure))
     18   ["missing"] = IO.fail "Set TRICU_DEMO_OUTPUT to an explicit output path"
     19   _ = IO.fail "Invalid environment reply"))
     20 run path text = IO.io (writeThenRead path text)