
On Fri, Sep 19, 2008 at 7:02 PM, Andre Nathan
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?
I believe modify is lazy. Try replacing it with a stricter version,
modify' f = do
s <- get
put $! f s
--
Dave Menendez