Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.haskell > #516
| From | Barry Fishman <barry@ecubist.org> |
|---|---|
| Newsgroups | comp.lang.haskell |
| Subject | Re: Get mapM to be lazy for IO |
| References | <24548724-4bdd-402d-8a76-1403b7e87169@googlegroups.com> <7nmup95via.fsf@ecube.ecubist.org> <7nimzx5u6q.fsf@ecube.ecubist.org> |
| Message-ID | <7nefal5t0g.fsf@ecube.ecubist.org> (permalink) |
| Organization | Easynews - www.easynews.com |
| Date | 2018-12-13 10:46 -0500 |
On 2018-12-13 10:21:17 -05, Barry Fishman wrote:
> Oops, I was wrong. If I replace the:
>
> xs <- getWordList 1
>
> with:
>
> xs <- take 3 `fmap` getWordList 1
>
> the values continue to be read. So the IO can't be read lazily as far
> as I can tell.
All I can seem to do is produce a infinite lazy list of IO actions,
prompting for and reading the words:
--8<---------------cut here---------------start------------->8---
#! /usr/bin/env runghc
import System.IO (hFlush, stdout)
main :: IO ()
main = do
putStrLn "Hello. Please enter each word."
xs <- sequence . take 3 $ map getWordIO [1..]
mapM_ putStrLn xs
where getWordIO :: Int -> IO String
getWordIO n = do
putStr $ "Input number " ++ show n ++ ": "
hFlush stdout
getLine
--8<---------------cut here---------------end--------------->8---
So the list that I 'take 3' from is a '[IO String]' and I sequence though
it to produce an 'IO [String]'.
--
Barry Fishman
Back to comp.lang.haskell | Previous | Next — Previous in thread | Find similar | Unroll thread
Get mapM to be lazy for IO kfjwheeler@gmail.com - 2018-12-11 05:19 -0800
Re: Get mapM to be lazy for IO Mark Carroll <mtbc@bcs.org> - 2018-12-11 13:36 +0000
Re: Get mapM to be lazy for IO Kaylen Wheeler <kfjwheeler@gmail.com> - 2018-12-12 17:52 -0800
Re: Get mapM to be lazy for IO Paul Rubin <no.email@nospam.invalid> - 2018-12-12 19:29 -0800
Re: Get mapM to be lazy for IO Kaylen Wheeler <kfjwheeler@gmail.com> - 2018-12-12 18:21 -0800
Re: Get mapM to be lazy for IO Paul Rubin <no.email@nospam.invalid> - 2018-12-12 19:31 -0800
Re: Get mapM to be lazy for IO Barry Fishman <barry@ecubist.org> - 2018-12-13 09:52 -0500
Re: Get mapM to be lazy for IO Barry Fishman <barry@ecubist.org> - 2018-12-13 10:21 -0500
Re: Get mapM to be lazy for IO Barry Fishman <barry@ecubist.org> - 2018-12-13 10:46 -0500
csiph-web