[Haskell-cafe] Re: Library design question
Andre Nathan
andre at digirati.com.br
Fri Sep 19 19:02:40 EDT 2008
On Fri, 2008-09-19 at 23:16 +0200, Daniel Fischer wrote:
> Yes. What's IO gotta do with it?
I did it because of randomIO :(
> (or what about StateT (Graph a b) (State StdGen) ?).
Now there's something I wouldn't have thought of... I changed the
RandomGraph type to
type RandomGraph a b = StateT (Graph a b) (State StdGen) ()
and randomFloat to
randomDouble :: State StdGen Double
randomDouble = State random
and randomGraph to
randomGraph :: StdGen -> Int -> Double -> Graph Int Int
randomGraph gen n p = evalState (execStateT create Graph.empty) gen
where create = mapM_ (uncurry $ createVertex p) vls
vls = zip [1..n] (repeat 42)
However, when I try to create a graph with 1000 vertices I get a stack
overflow, which didn't happen in the IO version. Any idea why that happens?
Thanks,
Andre
More information about the Haskell-Cafe
mailing list