[Haskell-cafe] better way to do this?

Eugene Kirpichov ekirpichov at gmail.com
Sun Oct 4 05:55:11 EDT 2009


[x,y,t,b,l,r] <- mapM (getStdRandom . randomR) [(-10,10), (-70,70), ...]
return (BoxBounds ...)

2009/10/4 Michael Mossey <mpm at alumni.caltech.edu>:
> I'm looking for a hint to write the following code with less redundancy. I
> have a constructor called BoxBounds, and I want to make one with random
> values.
>
> randomBox :: IO BoxBounds
> randomBox = do
>  x <- getStdRandom (randomR (-10,10))
>  y <- getStdRandom (randomR (-70,70))
>  t <- getStdRandom (randomR (5,10))
>  b <- getStdRandom (randomR (5,10))
>  l <- getStdRandom (randomR (5,10))
>  r <- getStdRandom (randomR (5,10))
>  return (BoxBounds x y l r t b)
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>



-- 
Eugene Kirpichov
Web IR developer, market.yandex.ru


More information about the Haskell-Cafe mailing list