Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Getting a specified number of lines from     stdin
      (frantisek kocun)
   2. Re:  Getting a specified number of lines from     stdin
      (Rein Henrichs)
   3. Re:  Getting a specified number of lines from     stdin
      (Rein Henrichs)


----------------------------------------------------------------------

Message: 1
Date: Fri, 11 Mar 2016 16:34:23 +0100
From: frantisek kocun <frantisek.ko...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Getting a specified number of lines
        from    stdin
Message-ID:
        <camcun70z5-076w0wgdspnex5sh+dkvg3evcxhou38c73qka...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Here is the answer

http://stackoverflow.com/questions/34910992/iterate-io-actions-and-laziness

You need to write recursive function, not to use iterage or to

liftM (take 5) $ sequence $ repeat (unsafeInterleaveIO getLine)


On Sun, Mar 6, 2016 at 11:38 AM, Nicolaas du Preez <njdupr...@yahoo.com>
wrote:

> Good day All,
>
> Why does
>
>     liftM (take 5) $ sequence $ repeat getLine
>
> not stop at reading only 5 lines from stdin but keeps on reading more?
>
> What I?m really trying to achieve is to get input from the user until
> an empty line is read with the code below.  But this doesn?t work
> as I expected, similar to the above.
>
>     liftM (takeWhile (/= "")) $ sequence $ repeat getLine
>
>
> Regards,
> Nicolaas du Preez
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20160311/9de4b881/attachment-0001.html>

------------------------------

Message: 2
Date: Fri, 11 Mar 2016 21:48:40 +0000
From: Rein Henrichs <rein.henri...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Getting a specified number of lines
        from    stdin
Message-ID:
        <CAJp6G8z=ddfparxm7--mo-vw0n2g0zdcqlzznxpa+wf1i5y...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

That is an unnecessary use of unsafeInterleaveIO. The solution is actually
quite simple:

    getLines n = replicateM n getLine
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20160311/0bd4be3a/attachment-0001.html>

------------------------------

Message: 3
Date: Fri, 11 Mar 2016 21:50:06 +0000
From: Rein Henrichs <rein.henri...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Getting a specified number of lines
        from    stdin
Message-ID:
        <CAJp6G8x_AiVg6MBYpcTsNJSn=nfuzueljcd4x+jwewu7wm7...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Note that replicateM n k = sequence (replicate n k), so this solution is
equivalent to Henk-Jan van Tuyl's original solution.

On Fri, Mar 11, 2016 at 1:48 PM Rein Henrichs <rein.henri...@gmail.com>
wrote:

> That is an unnecessary use of unsafeInterleaveIO. The solution is actually
> quite simple:
>
>     getLines n = replicateM n getLine
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20160311/23d8fb00/attachment-0001.html>

------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 93, Issue 9
****************************************

Reply via email to