on master help sign in
Simplify replWith
2cefa5cEdwin Brady
libs/prelude/Prelude/Interactive.idr+3−4
@@ -121,14 +121,14 @@ processStdin = processHandle stdin
121||| output and a new state. Returns Nothing if the repl should exit
121||| output and a new state. Returns Nothing if the repl should exit
122partial
122partial
123replWith : (state : a) -> (prompt : String) ->
123replWith : (state : a) -> (prompt : String) ->
124− (onInput : a -> String -> Maybe (String, a)) -> IO a
124+ (onInput : a -> String -> Maybe (String, a)) -> IO ()
125replWith acc prompt fn
125replWith acc prompt fn
126 = do putStr prompt
126 = do putStr prompt
127 x <- getLine
127 x <- getLine
128 case fn acc x of
128 case fn acc x of
129 Just (out, acc') => do putStr out
129 Just (out, acc') => do putStr out
130 replWith acc' prompt fn
130 replWith acc' prompt fn
131− Nothing => return acc
131+ Nothing => return ()
132
132
133||| A basic read-eval-print loop
133||| A basic read-eval-print loop
134||| @ prompt the prompt to show
134||| @ prompt the prompt to show
@@ -138,6 +138,5 @@ partial
138repl : (prompt : String) ->
138repl : (prompt : String) ->
139 (onInput : String -> String) -> IO ()
139 (onInput : String -> String) -> IO ()
140repl prompt fn
140repl prompt fn
141− = do replWith () prompt (\x, s => Just (fn s, ()))
141+ = replWith () prompt (\x, s => Just (fn s, ()))
142− return ()
143
142