[Haskell-cafe] List comparisons and permutation group code

Brandon Moore brandonm at yahoo-inc.com
Thu Oct 19 17:17:14 EDT 2006


David House wrote:
> On 19/10/06, Brandon Moore <brandonm at yahoo-inc.com> wrote:
>> isIdentity xs = xs == takeLengthOf xs [1..]
>>  where takeLengthOf xs ys = zipWith const ys xs
>
> You probably mean zipWith (flip const) xs ys.
Either way, as long as I didn't write "zipWith const xs ys".
>> for finite lists,
>> takeLengthOf xs ys == take (length xs) ys
>
> This ruins the laziness again:
>
> Hugs.Base> let takeLengthOf xs ys = take (length xs) ys; isIdentity xs
> = xs == takeLengthOf xs [1..] in isIdentity (1:3:2:[4..10000])
> False
> (210064 reductions, 278075 cells)
> Hugs.Base> let takeLengthOf = zipWith (flip const); isIdentity xs = xs
> == takeLengthOf xs [1..] in isIdentity (1:3:2:[4..1000])
> False
> (60 reductions, 114 cells)
>
It's meant as an explanation, and partial specification:

Prelude> let takeLength xs ys = zipWith const ys xs
Prelude> Test.QuickCheck.test (\xs ys -> takeLength xs ys == take 
(length xs) ys)
OK, passed 100 tests.

This reminds me that QuickCheck only generates finite lists.

Brandon


More information about the Haskell-Cafe mailing list