[Haskell-cafe] Possible FGL bug

David Menendez dave at zednenem.com
Wed Nov 25 15:36:42 EST 2009

On Wed, Nov 25, 2009 at 11:02 AM, Neil Brown <nccb2 at kent.ac.uk> wrote:
> David Menendez wrote:
>> From what I can tell, insEdge inserts an edge between two nodes which
>> are already in the graph. The code is calling insEdge on
>> arbitrarily-labeled nodes, which may not exist in the graph.
> That's what I thought initially, but in fact what it is doing is exactly
> what you suggest:
>> Instead of picking arbitrary node labels, try selecting arbitrary
>> elements from the list of node labels.
> That "nGen = elements ns" line assigns into nGen a random generator that
> will pick from ns, the list of nodes.

You're right. I've tried this in ghci, and I'm not able to reproduce
the error. I did get an exception from QuickCheck when it tried to
call elements on an empty list, though.

This code works fine for me:

a :: Gen ([LNode Char], [LEdge Char], Gr Char Char)
a = do
    NonEmpty ns' <- arbitrary
    let ns = nub ns'
    let nGen = elements ns
    lns <- mapM (\n -> liftM ((,) n) arbitrary) ns
    les <- listOf $ liftM3 (,,) nGen nGen arbitrary
    return (lns, les, mkGraph lns les)

I suspect that there's no value to generating an arbitrary list of
node IDs, as opposed to something like:

    ns <- liftM (\(Positive n) -> [0..n]) arbitrary

Dave Menendez <dave at zednenem.com>

More information about the Haskell-Cafe mailing list