[Haskell-cafe] Re: Why do I need a 'do'?

Henning Thielemann lemming at henning-thielemann.de
Thu Apr 30 08:34:51 EDT 2009


On Thu, 30 Apr 2009, Maurício wrote:

>>> import System.Random
>>>
>>> rollDice :: IO Int
>>> rollDice = getStdRandom (randomR (1,6))
>>>
>>> rollNDice :: Int -> [IO Int]
>>> rollNDice 0 = []
>>> rollNDice n = rollDice : rollNDice (n-1)
>>
>>
>> replicateM n rollDice
>>
>> http://www.haskell.org/haskellwiki/Avoiding_IO#State_monad
>
> Or, if you want the original idea:
>
> sequence (rollNDice 10)
>
> Check the type of sequence at Control.Monad.

I'd still propose
   http://www.haskell.org/haskellwiki/Haskell_programming_tips#Avoid_explicit_recursion


More information about the Haskell-Cafe mailing list