File: Main.agda

package info (click to toggle)
agda-stdlib 2.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,196 kB
  • sloc: haskell: 375; makefile: 32; sh: 28; lisp: 1
file content (24 lines) | stat: -rw-r--r-- 683 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
{-# OPTIONS --guardedness #-}

module Main where

open import Data.String.Base
open import Function.Base using (_$_; case_of_)
open import IO
open import System.Exit using (exitSuccess)

main : Main
main = run $ do
  -- Ensure no buffering so that the prompt "echo< "
  -- gets outputed immediately
  hSetBuffering stdout noBuffering
  forever $ do
    putStr "echo< "
    -- Get a line from the user and immediately inspect it
    -- If it's a magic "exit" keyword then we exit, otherwise
    -- we print the echo'd message and let the `forever` action
    -- continue
    str ← getLine
    case str of λ where
      "exit" → exitSuccess
      _ → putStrLn ("echo> " ++ str)