
Hello, I have this function : fourDifferent:: Integer -> Integer -> Integer -> Integer -> Bool fourDifferent a b c d = ( a == b ) && ( a == c ) && (a == d) which I wants to test with this function : prop_fourDifferent :: Integer -> Integer -> Integer -> Integer -> Bool prop_fourDifferent a b c d = fourDifferent a b c d == ( a == b ) && ( a == c ) && (a == d) so I do quickCheck propFourDifferent and see this outcome : *Solution> quickCheck prop_fourDifferent *** Failed! Falsifiable (after 2 tests and 2 shrinks): 0 0 0 1 *Solution> fourDifferent 0 0 0 1 False *Solution> let a = 0 *Solution> let b = 0 *Solution> let c = 0 *Solution> let d = 1 *Solution> (a == b) && ( a == c) && ( a == d ) False *Solution> So why is it failing. both gives false , Roelof

On 2015-09-10 09:23, Roelof Wobben wrote:
which I wants to test with this function :
prop_fourDifferent :: Integer -> Integer -> Integer -> Integer -> Bool prop_fourDifferent a b c d = fourDifferent a b c d == ( a == b ) && ( a == c ) && (a == d)
The problem is that (==) has a higher precedence (4) than (&&) (which has precedence 3). So your definition is equivalent to prop_fourDifferent a b c d = (fourDifferent a b c d == ( a == b )) && ( a == c ) && (a == d) You need some extra parentheses there, try prop_fourDifferent a b c d = fourDifferent a b c d == (( a == b ) && ( a == c ) && (a == d)) -- Frerich Raabe - raabe@froglogic.com www.froglogic.com - Multi-Platform GUI Testing

Op 10-9-2015 om 09:54 schreef Frerich Raabe:
On 2015-09-10 09:23, Roelof Wobben wrote:
which I wants to test with this function :
prop_fourDifferent :: Integer -> Integer -> Integer -> Integer -> Bool prop_fourDifferent a b c d = fourDifferent a b c d == ( a == b ) && ( a == c ) && (a == d)
The problem is that (==) has a higher precedence (4) than (&&) (which has precedence 3). So your definition is equivalent to
prop_fourDifferent a b c d = (fourDifferent a b c d == ( a == b )) && ( a == c ) && (a == d)
You need some extra parentheses there, try
prop_fourDifferent a b c d = fourDifferent a b c d == (( a == b ) && ( a == c ) && (a == d))
Thanks, Learned that in this sort of situations I have to check the precendence. Roelof

Hi Roelof,
False == True && False False
False == (True && False) True
:info (==) class Eq a where (==) :: a -> a -> Bool infix 4 ==
:info (&&) (&&) :: Bool -> Bool -> Bool infixr 3 &&
So (==) at level 4 binds tighter than (&&) at level 3.
See: https://www.haskell.org/onlinereport/decls.html#fixity
-- Kim-Ee
On Thu, Sep 10, 2015 at 2:23 PM, Roelof Wobben
Hello,
I have this function :
fourDifferent:: Integer -> Integer -> Integer -> Integer -> Bool fourDifferent a b c d = ( a == b ) && ( a == c ) && (a == d)
which I wants to test with this function :
prop_fourDifferent :: Integer -> Integer -> Integer -> Integer -> Bool prop_fourDifferent a b c d = fourDifferent a b c d == ( a == b ) && ( a == c ) && (a == d)
so I do quickCheck propFourDifferent and see this outcome :
*Solution> quickCheck prop_fourDifferent *** Failed! Falsifiable (after 2 tests and 2 shrinks): 0 0 0 1
*Solution> fourDifferent 0 0 0 1 False *Solution> let a = 0 *Solution> let b = 0 *Solution> let c = 0 *Solution> let d = 1 *Solution> (a == b) && ( a == c) && ( a == d ) False *Solution>
So why is it failing. both gives false ,
Roelof
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
participants (3)
-
Frerich Raabe
-
Kim-Ee Yeoh
-
Roelof Wobben