on master help sign in
Simplify replWith

Its purpose is mostly pedagogical, to make 'main' a one liner when writing interactive programs without knowing how to use IO yet, so it should return () so that this works.

commit2cefa5c0c9dd5552faf1d0abba150bf0efd31015 authorEdwin Brady <ecb10@st-andrews.ac.uk> dateSat 15 Aug 2015, 23:14 (11 years ago) parentf3f828c
1 file changed+3−4
libs/prelude/Prelude/Interactive.idr+3−4
libs/prelude/Prelude/Interactive.idr+3−4
@@ -121,14 +121,14 @@ processStdin = processHandle stdin
121121||| output and a new state. Returns Nothing if the repl should exit
122122partial
123123replWith : (state : a) -> (prompt : String) ->
124− (onInput : a -> String -> Maybe (String, a)) -> IO a
124+ (onInput : a -> String -> Maybe (String, a)) -> IO ()
125125replWith acc prompt fn
126126 = do putStr prompt
127127 x <- getLine
128128 case fn acc x of
129129 Just (out, acc') => do putStr out
130130 replWith acc' prompt fn
131− Nothing => return acc
131+ Nothing => return ()
132132
133133||| A basic read-eval-print loop
134134||| @ prompt the prompt to show
@@ -138,6 +138,5 @@ partial
138138repl : (prompt : String) ->
139139 (onInput : String -> String) -> IO ()
140140repl prompt fn
141− = do replWith () prompt (\x, s => Just (fn s, ()))
142− return ()
141+ = replWith () prompt (\x, s => Just (fn s, ()))
143142