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

Bruno Martínez br1 at internet.com.uy
Thu Sep 21 10:40:49 EDT 2006

On Thu, 21 Sep 2006 11:20:33 -0300, Henning Thielemann  
<lemming at henning-thielemann.de> wrote:

> 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.

But I cannot process input again without getContents.  This function's use  
of getContents forces me to use only getContents everywhere.  For example,  
I can't use hWaitForInput in another IO action.

>> 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.

I try to minimize the amount of IO I do, but there's a point I don't know  
how to strip my functions of their remaining IOness.  That's why I ask :)


More information about the Haskell-Cafe mailing list