[Haskell-cafe] Random pattern generation with list comprehensions

Michael Sloan mgsloan at gmail.com
Sat Dec 13 03:16:10 UTC 2014


Hello!

It sounds like you're looking for the ParallelListComp language extension[1]

Another option might be to leverage the Arbitrary typeclass in
QuickCheck[2].  It has instances for tuples, so if each component of
the tuple has an Arbitrary instance, you can generate the whole tuple
with one invocation of "arbitrary".  The CoArbitrary typeclass is also
rather handy and clever, as it allows you to create random functions,
as long as the arguments are instances of CoArbitrary and the result
is an instance of Arbitrary.  Your concept of specifying run length is
very similar to QuickCheck's "size parameter".

I hope that's helpful!

-Michael

[1] https://downloads.haskell.org/~ghc/7.8.3/docs/html/users_guide/syntax-extns.html#parallel-list-comprehensions
[2] http://hackage.haskell.org/package/QuickCheck


More information about the Haskell-Cafe mailing list