[Haskell-beginners] Re: Eliminate repetitive monad/list code

John Smith voldermort at hotmail.com
Thu Nov 4 15:20:53 EDT 2010


Thank you very much, this is just the right solution.

On 04/11/2010 18:33, Tobias Brandt wrote:
> On 4 November 2010 17:19, John Smith<voldermort at hotmail.com>  wrote:
>> foo :: IO A
>>
>> bar :: Bool ->  A ->  Int ->  Bool ->  IO ()
>>
>> bar' a b = bar True a b False
>>
>> do
>>   x<- foo
>>   y<- foo
>>   z<- foo
>>
>>   bar x 1
>>   bar y 2
>>   bar z 3
>>
>> but I don't know what to do next. Is there some form of list comprehension
>> or combination of map and lift which will eliminate the repetition?
>
>
> mapM_ (\x ->  foo>>= flip bar x) [1,2,3]



More information about the Beginners mailing list