36 lines · 1.1 KB · Text
RawDownload
module System.REPL import System.File ||| A basic read-eval-print loop, maintaining a state||| @ state the input state||| @ prompt the prompt to show||| @ onInput the function to run on reading input, returning a String to||| output and a new state. Returns Nothing if the repl should exitexportreplWith : (state : a) -> (prompt : String) ->           (onInput : a -> String -> Maybe (String, a)) -> IO ()replWith acc prompt fn   = do eof <- fEOF stdin        if eof          then pure ()          else do putStr prompt                  fflush stdout                  x <- getLine                  case fn acc x of                       Just (out, acc') =>                           do putStr out                              replWith acc' prompt fn                       Nothing => pure () ||| A basic read-eval-print loop||| @ prompt the prompt to show||| @ onInput the function to run on reading input, returning a String to||| outputexportrepl : (prompt : String) ->       (onInput : String -> String) -> IO ()repl prompt fn   = replWith () prompt (\x, s => Just (fn s, ()))  

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t