[Haskell-cafe] Possible FGL bug

Ivan Lazar Miljenovic ivan.miljenovic at gmail.com
Thu Nov 26 20:51:58 EST 2009


Well, I've made two changes, either of which might have done the
trick...

1) Sort the lists of nodes and edge;
2) Remove multiple edges (that is, have at most one edge f -> t).

The latter requirement was because the property I was testing only
worked if there were no multiple edges.

Either way, it seems to work now without having any errors turn up, so
it seems to have done the trick...

David Menendez <dave at zednenem.com> writes:

> 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

-- 
Ivan Lazar Miljenovic
Ivan.Miljenovic at gmail.com
IvanMiljenovic.wordpress.com


More information about the Haskell-Cafe mailing list