[Haskell-cafe] Re: Need some help with an infinite list

Matthew Brecknell haskell at brecknell.org
Sat Jun 20 23:46:31 EDT 2009


Thomas Hartman wrote:
> could someone explain sharing?

A good tool for visualising the difference between shared and non-shared
results would be vacuum, using one of its front ends, vacuum-cairo or
vacuum-ubigraph.

http://hackage.haskell.org/package/vacuum
http://hackage.haskell.org/package/vacuum-cairo
http://hackage.haskell.org/package/vacuum-ubigraph

To see sharing, you will need to view a set of outputs (not just one
string). To keep the graph to a manageable size, use a smaller alphabet:

digits = "01"

-- All words of length n, with shared substrings
shared :: Int -> [String]
shared n = sss !! n where
  sss = [""] : [ [ c:s | c <- digits, s <- ss ] | ss <- sss ]

-- All words of length n, with unshared substrings
unshared :: Int -> [String]
unshared 0 = [""]
unshared n = [ c:s | c <- digits, s <- unshared (n-1) ]

And then in GHCi:

Vacuum.Cairo> shared 3 == unshared 3
True
Vacuum.Cairo> view $ shared 3
Vacuum.Cairo> view $ unshared 3

I'd send some PNGs, except my vacuum installation is currently broken.
Perhaps someone else can?

Regards,
Matthew




More information about the Haskell-Cafe mailing list