QuickCheck, (Ord a)=> [a] -> Property problem

Hi, I found there is similar question as: http://groups.google.com/group/haskell-cafe/browse_thread/thread/7439262e9ac80dd2/91ca18e11ff00649?lnk=gst&q=QuickCheck+Ord+a#91ca18e11ff00649 I am still think it's very strange. For example: prop_foo :: (Ord a) => [a] -> Property prop_foo xs = not (null xs) ==> maximum xs == minimum xs This is an extreme case that the property is always wrong. However, QuickCheck produces: *Main> test prop_foo OK, passed 100 tests. Why this happen? If I use verboseCheck, I can find the sample test data are as the following: *Main>verboseCheck prop_foo ... 97: [(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),()] 98: [(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(), (),(),(),(),(),(),()] 99: [(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(), (),(),()] OK, passed 100 tests. So Arbitrary () is generated as the instance of Ord a. I have to change the prototype as prop_foo :: (Num a) => [a] -> Property This works at least, However, since 'a'<'b', they are order-able, what if I want to test prop_foo works for char? I am using Haskell Platform (version 6.10.4), with QuickCheck version 1.2.0.0 Thanks -- Larry, LIU Xinyu https://sites.google.com/site/algoxy/home

On Wednesday 20 April 2011 11:43:08, larry.liuxinyu wrote:
Hi,
I found there is similar question as: http://groups.google.com/group/haskell-cafe/browse_thread/thread/7439262 e9ac80dd2/91ca18e11ff00649?lnk=gst&q=QuickCheck+Ord+a#91ca18e11ff00649
I am still think it's very strange. For example:
prop_foo :: (Ord a) => [a] -> Property prop_foo xs = not (null xs) ==> maximum xs == minimum xs
This is an extreme case that the property is always wrong.
Not always, replicate n x has this property.
However, QuickCheck produces: *Main> test prop_foo OK, passed 100 tests.
This works at least, However, since 'a'<'b', they are order-able, what if I want to test prop_foo works for char?
ghci> test (prop_foo :: [Char] -> Property) You have to determine the type, by an explicit signature or by context.

"larry.liuxinyu"
prop_foo :: (Ord a) => [a] -> Property prop_foo xs = not (null xs) ==> maximum xs == minimum xs
This is an extreme case that the property is always wrong.
However, QuickCheck produces: *Main> test prop_foo OK, passed 100 tests.
Why this happen? If I use verboseCheck, I can find the sample test data are as the following: *Main>verboseCheck prop_foo ... 97: [(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),()] 98: [(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(), (),(),(),(),(),(),()] 99: [(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(), (),(),()] OK, passed 100 tests.
This is an unfortunate feature of GHCi: if the thing you want to evaluate has a polymorphic type then all the type variables default to (), see: http://www.haskell.org/ghc/docs/7.0.3/html/users_guide/interactive-evaluatio... So prop_foo is only tested for lists of (). Nasty. The usual way to work around it is to declare all your properties monomorphic, so write: prop_foo :: [Integer] -> Property
This works at least, However, since 'a'<'b', they are order-able, what if I want to test prop_foo works for char?
Testing with Integers should always[*] be enough because of parametricity. Nick [*] For certain values of "always" :)

Hi,
Thanks a lot.
The following type protocol also works.
prop_foo :: (Ord a)=>(Num a) => [a] -> Property
Somebody told me that:
Eduard Sergeev • BTW, more recent QuickCheck (from Haskell Platform
2011.2.0.X - contains QuickCheck-2.4.0.1) seems to identifies the
problem correctly:
*** Failed! Falsifiable (after 3 tests and 2 shrinks):
[0,1]
False
--
Larry
On Apr 20, 11:36 pm, Nick Smallbone
"larry.liuxinyu"
writes: prop_foo :: (Ord a) => [a] -> Property prop_foo xs = not (null xs) ==> maximum xs == minimum xs
This is an extreme case that the property is always wrong.
However, QuickCheck produces: *Main> test prop_foo OK, passed 100 tests.
Why this happen? If I use verboseCheck, I can find the sample test data are as the following: *Main>verboseCheck prop_foo ... 97: [(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),()] 98: [(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(), (),(),(),(),(),(),()] 99: [(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(),(), (),(),()] OK, passed 100 tests.
This is an unfortunate feature of GHCi: if the thing you want to evaluate has a polymorphic type then all the type variables default to (), see: http://www.haskell.org/ghc/docs/7.0.3/html/users_guide/interactive-ev... So prop_foo is only tested for lists of (). Nasty.
The usual way to work around it is to declare all your properties monomorphic, so write: prop_foo :: [Integer] -> Property
This works at least, However, since 'a'<'b', they are order-able, what if I want to test prop_foo works for char?
Testing with Integers should always[*] be enough because of parametricity.
Nick
[*] For certain values of "always" :)
_______________________________________________ Haskell-Cafe mailing list Haskell-C...@haskell.orghttp://www.haskell.org/mailman/listinfo/haskell-cafe

"larry.liuxinyu"
Somebody told me that: Eduard Sergeev • BTW, more recent QuickCheck (from Haskell Platform 2011.2.0.X - contains QuickCheck-2.4.0.1) seems to identifies the problem correctly:
*** Failed! Falsifiable (after 3 tests and 2 shrinks): [0,1] False
I don't think this can be true: the problem occurs in GHCi and there's no way for QuickCheck to detect it. And when I tested it I got the same problem. There must be some difference between the properties you both tested... Nick

On Thu, 2011-04-21 at 23:56 +0200, Nick Smallbone wrote:
"larry.liuxinyu"
writes: Somebody told me that: Eduard Sergeev • BTW, more recent QuickCheck (from Haskell Platform 2011.2.0.X - contains QuickCheck-2.4.0.1) seems to identifies the problem correctly:
*** Failed! Falsifiable (after 3 tests and 2 shrinks): [0,1] False
I don't think this can be true: the problem occurs in GHCi and there's no way for QuickCheck to detect it. And when I tested it I got the same problem. There must be some difference between the properties you both tested...
Nick
There was an additional class contrain (Num a). Num default to Int IIRC. Regards

On 22 April 2011 09:36, Maciej Marcin Piechotka
On Thu, 2011-04-21 at 23:56 +0200, Nick Smallbone wrote:
"larry.liuxinyu"
writes: Somebody told me that: *** Failed! Falsifiable (after 3 tests and 2 shrinks): [0,1] False
I don't think this can be true: the problem occurs in GHCi and there's no way for QuickCheck to detect it. And when I tested it I got the same problem. There must be some difference between the properties you both tested...
There was an additional class contrain (Num a). Num default to Int IIRC.
Integer I believe. -- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com IvanMiljenovic.wordpress.com

Hi,
I tested with Haskell platform 2011 with QuickCheck 2.4.0.1.
It produced 100 cases passed, but can't report failed case.
verboseCheck still told me that [(), (), ... ()] are generated as
instance to (Ord a)
The only way is to specify the non-ambitious type for example, Int,
like below:
test (prop_foo::[Int]->Property)
Cheers.
--
Larry.
On Apr 22, 5:56 am, Nick Smallbone
"larry.liuxinyu"
writes: Somebody told me that: Eduard Sergeev • BTW, more recent QuickCheck (from Haskell Platform 2011.2.0.X - contains QuickCheck-2.4.0.1) seems to identifies the problem correctly:
*** Failed! Falsifiable (after 3 tests and 2 shrinks): [0,1] False
I don't think this can be true: the problem occurs in GHCi and there's no way for QuickCheck to detect it. And when I tested it I got the same problem. There must be some difference between the properties you both tested...
Nick
_______________________________________________ Haskell-Cafe mailing list Haskell-C...@haskell.orghttp://www.haskell.org/mailman/listinfo/haskell-cafe
participants (5)
-
Daniel Fischer
-
Ivan Lazar Miljenovic
-
larry.liuxinyu
-
Maciej Marcin Piechotka
-
Nick Smallbone