[Haskell-beginners] lazy mapM
Kim-Ee Yeoh
ky3 at atamo.com
Mon Apr 1 02:29:54 CEST 2013
On Mon, Apr 1, 2013 at 6:26 AM, Ovidiu D <ovidiudeac at gmail.com> wrote:
> 1. Make f behave lazy
> Its input list is made of lines read from stdin and I want it to process
> lines one by one as they are entered by the user.
Eschewing laziness (which adds only complexity in this case), here's
something that'll work, if a little ugly:
import System.Exit
f :: String -> IO ()
f "exit" = exitSuccess
f a = putStrLn $ "you entered: " ++ a
main = do
s <- getLine
f s
main
Going down this path would involve IORef's, among others from the "sin bin".
Something more pure and haskell-y would typically involve an analysis
of the DSL abstract syntax and state space and implementation using a
combination of State and Free monads.
-- Kim-Ee
More information about the Beginners
mailing list