Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  wierd quickcheck outcome (Roelof Wobben)
   2. Re:  wierd quickcheck outcome (Frerich Raabe)
   3. Re:  wierd quickcheck outcome (Kim-Ee Yeoh)


----------------------------------------------------------------------

Message: 1
Date: Thu, 10 Sep 2015 09:23:29 +0200
From: Roelof Wobben <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] wierd quickcheck outcome
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8; format=flowed

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



------------------------------

Message: 2
Date: Thu, 10 Sep 2015 09:54:37 +0200
From: Frerich Raabe <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] wierd quickcheck outcome
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII; format=flowed

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 - [email protected]
www.froglogic.com - Multi-Platform GUI Testing


------------------------------

Message: 3
Date: Thu, 10 Sep 2015 16:25:03 +0700
From: Kim-Ee Yeoh <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] wierd quickcheck outcome
Message-ID:
        <CAPY+ZdSdvKZRv8q+NC2Gzzs2mVkSp38O22UHZ3rYpf=g3gr...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

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 <[email protected]> wrote:

> 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
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150910/92c7081f/attachment-0001.html>

------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 87, Issue 3
****************************************

Reply via email to