[Haskell-cafe] Re: [newbie] How to test this function?

Henning Thielemann lemming at henning-thielemann.de
Thu Sep 21 10:20:33 EDT 2006


On Thu, 21 Sep 2006, Bruno Martínez wrote:

> >     getList :: IO [Char]
> >     getList = take5 `fmap` getContents -- a thin IO "skin"
> > 
> >     take5 :: [Char] -> [Char]
> >     take5 = take 5 . filter (`elem` ['a'..'e']) -- the actual worker
> 
> The problem is that getContents 'eats' stdin, which can't be used again. 

You can process the result of getContents as many times as you want.

> I'm forced to change all my IO code to the getContents way, which is not
> possible.

If your program contains so much IO code you should seriously consider
refactoring.


More information about the Haskell-Cafe mailing list