Bug in Control.Monad.State
Iavor Diatchki
iavor.diatchki at gmail.com
Wed Nov 23 17:20:51 EST 2005
Hello,
I am still confused, sorry :-) It appears that the code has a type error:
repeatM randomItem :: State g [Int]
so, isn't 'item' of type '[Int]'. On the other hand, 'updateState' is
expecting an 'Int' as an argument...
-Iavor
> createItems :: RandomGen g => State g [Item]
> createItems =
> liftM catMaybes $ runListT $
> flip evalStateT initialState $ runMaybeT $
> do
> item <- liftRandom $ repeatM randomItem
> updateState item
> needMoreItems >>= guard
> return item
> where
> liftRandom = lift . lift . lift
>
> -- Create one random item.
> randomItem :: RandomGen g => State g Item
> randomItem = State $ randomR (1, 5)
>
> -- repeatM is still missing from Control.Monad.
> -- I hope they will put it in soon.
> repeatM :: Monad m => m a -> m [a]
> repeatM = sequence . repeat
More information about the Libraries
mailing list