[Haskell-cafe] Random question

Ariel J. Birnbaum valgarv at gmx.net
Thu Sep 25 16:26:59 EDT 2008


> And the one liner:
> (rand 1 10) >>= return . (\v -> take v [1..10])

What about:
    take <$> rand 1 10 <*> pure [1..10]
(more readable IMHO).

One could even define:
    f <%> x = f <*> pure x
and have
    take <$> rand 1 10 <%> [1..10]

Also, why not using getRandomR(1,10) instead?
    take <$> getRandomR (1,10) <%> [1..10] :: (MonadRandom m) => m Int
That way you separate the generation from the IO.

My getRandomR(0,3) <%> cents.
-- 
Ariel J. Birnbaum


More information about the Haskell-Cafe mailing list