[Haskell-beginners] lazy mapM

Ovidiu D ovidiudeac at gmail.com
Mon Apr 1 02:49:07 CEST 2013


Thanks. Since this is an exercise I would be really curious what is the
idiomatic Haskell approach.


On Mon, Apr 1, 2013 at 3:29 AM, Kim-Ee Yeoh <ky3 at atamo.com> wrote:

> 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
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130401/89531d6f/attachment.htm>


More information about the Beginners mailing list