greet.tri (927B)
1 !import 3dbb76ee4b350c161ed4f9c9f600034195b2fcf99202d46b8adcd25715a56f6b as IO 2 !import 11791107bece9dac78ff92dcec75d11830921e359976f561a934b36f9e8910df as Text 3 !export main 4 5 -- A conversation: ask for a name, then greet the person who replies. 6 -- Send a line or choose "End input" in the card's terminal. 7 -- Read and write Results are checked before continuing. 8 -- Return the name when IO finishes. Try changing the greeting. 9 greet writer [["line" name _] _] = do IO.require 10 Text.writeText writer "Hello, " 11 Text.writeText writer name 12 Text.writeText writer "!\n" 13 IO.pure name 14 greet writer [["eof"] _] = IO.require 15 (Text.writeText writer "End of input.\n") (_ : IO.pure "") 16 greet _ _ = IO.fail "Invalid line reply" 17 18 main = IO.io 19 do IO.require 20 reader <- IO.stdin 21 writer <- IO.stdout 22 Text.writeText writer "What is your name?\n" 23 line <- Text.readLine (Text.lineCursor reader) 4096 24 greet writer line