Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/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.  Question re "Pattern match(es) are       non-exhaustive" (Joel Neely)
   2. Re:  Question re "Pattern match(es) are   non-exhaustive"
      (Mike Meyer)
   3. Re:  Question re "Pattern match(es) are   non-exhaustive"
      (Brandon Allbery)
   4. Re:  Question re "Pattern match(es) are   non-exhaustive"
      (Kim-Ee Yeoh)
   5. Re:  Question re "Pattern match(es) are non-exhaustive"
      (Frerich Raabe)
   6.  Fwd: GHC 7.10 Prelude: we need your opinion (Kim-Ee Yeoh)


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

Message: 1
Date: Tue, 10 Feb 2015 06:58:37 -0600
From: Joel Neely <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] Question re "Pattern match(es) are
        non-exhaustive"
Message-ID:
        <CAEEzXAiATkSMgtFrJ5e3i=vbtmzoowpad6cmegkezhnfcu4...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

I understand the meaning of the warning, but got it in a situation I didn't
expect. The following source file contains the simplest case I could
construct quickly to illustrate my question:

Why does the first function (sumDigits) get the "non-exhaustive" warning?
It contains a definition for both empty and non-empty arguments, just as
the second (sumList), which does not get a warning.

{-# OPTIONS_GHC -Wall #-}

sumDigits :: [Integer] -> Integer
sumDigits []     = 0
sumDigits (n:ns)
  | n < 10       = n + sumDigits ns
  | n >= 10      = r + sumDigits (q : ns)
  where (q, r)   = n `quotRem` 10

sumList :: [Integer] -> Integer
sumList []     = 0
sumList (n:ns) = n + sumList ns


?For completeness, here is the ghci transcript, with the location reported:

Prelude> :load sumDigits.hs

[1 of 1] Compiling Main             ( sumDigits.hs, interpreted )


sumDigits.hs:4:1: Warning:

    Pattern match(es) are non-exhaustive

    In an equation for ?sumDigits?: Patterns not matched: _ : _

Ok, modules loaded: Main.

?
?Thanks in advance for any guidance on this.
-jn-?


-- 
Beauty of style and harmony and grace and good rhythm depend on simplicity.
- Plato
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20150210/f89f920d/attachment-0001.html>

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

Message: 2
Date: Tue, 10 Feb 2015 07:18:11 -0600
From: Mike Meyer <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Question re "Pattern match(es) are
        non-exhaustive"
Message-ID:
        <CAD=7U2A0wwkKxfpgZR8=+wp3ffb3xbsvmsavyosgfzhtb6u...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

On Tue, Feb 10, 2015 at 6:58 AM, Joel Neely <[email protected]> wrote:

> {-# OPTIONS_GHC -Wall #-}
>
> sumDigits :: [Integer] -> Integer
> sumDigits []     = 0
> sumDigits (n:ns)
>   | n < 10       = n + sumDigits ns
>   | n >= 10      = r + sumDigits (q : ns)
>   where (q, r)   = n `quotRem` 10
>
> sumList :: [Integer] -> Integer
> sumList []     = 0
> sumList (n:ns) = n + sumList ns
>
>
>
ghc can't decide whether or not the tests in the guards are complete or
not. If you rewrite the second condition as "otherwise", it'll recognize
the catch-all and you won't get a warning.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20150210/c089727b/attachment-0001.html>

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

Message: 3
Date: Tue, 10 Feb 2015 08:52:24 -0500
From: Brandon Allbery <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Question re "Pattern match(es) are
        non-exhaustive"
Message-ID:
        <cakfcl4ula-fxx+rw0h8nmynw5fgfnch1dck0ehexwjqmtgk...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

On Tue, Feb 10, 2015 at 8:18 AM, Mike Meyer <[email protected]> wrote:

> ghc can't decide whether or not the tests in the guards are complete or
> not.


Expanding on this: that < and >= cover all cases is something that is
convention for Ord instances, not something absolutely guaranteed to be
true. (In fact, they *don't* cover all cases for IEEE floating point math,
if either value is NaN. An SQL numeric value type would also not cover all
cases because of the behavior of NULL. In both those cases, *both*
conditions would return False.) The fact that you specified a type for
which it does happen to be true doesn't really matter, because there's no
way to convey a proof to the compiler that it's true for some types but not
others. (Some argue that this and some other things are signs that the Ord
typeclass is poorly designed; that is a fairly complex discussion.)

A compiler for something like C would assume that it covers all types (and
then behave weirdly in the above mentioned cases. Somewhat infamously,
there was a longstanding bug in a standard C library function (qsort()) for
decades because of this); Haskell compilers are a bit more pedantic and
warn you that Ord provides no proof that those two conditions cover all
cases.

-- 
brandon s allbery kf8nh                               sine nomine associates
[email protected]                                  [email protected]
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20150210/5db314bd/attachment-0001.html>

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

Message: 4
Date: Tue, 10 Feb 2015 22:52:06 +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] Question re "Pattern match(es) are
        non-exhaustive"
Message-ID:
        <capy+zdtajodl3no4e8snwrhwu2bvif9buvp8hrxgnfhh6yk...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

On Tue, Feb 10, 2015 at 7:58 PM, Joel Neely <[email protected]> wrote:

> sumDigits (n:ns)
>   | n < 10       = n + sumDigits ns
>   | n >= 10      = r + sumDigits (q : ns)
>   where (q, r)   = n `quotRem` 10
>

To reiterate what Mike and Brandon just said, it's not that both the [] and
(n:ns) cases have not been covered. They have.

It's that the (n:ns) case hasn't been covered completely because of the
guards.

This will work:

sumDigits (n:ns)
  | n < 10       = n + sumDigits ns
  | otherwise    = r + sumDigits (q : ns)

As will this:

sumDigits (n:ns)
  | n < 10       = n + sumDigits ns
  | n >= 10      = r + sumDigits (q : ns)
  | otherwise    = error "will never fire, only to suppress spurious
warning"

There's also -fno-warn-incomplete-patterns.

-- Kim-Ee
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20150210/b602c6bc/attachment-0001.html>

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

Message: 5
Date: Tue, 10 Feb 2015 17:14:56 +0100
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] Question re "Pattern match(es) are
        non-exhaustive"
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII; format=flowed

On 2015-02-10 14:52, Brandon Allbery wrote:
> On Tue, Feb 10, 2015 at 8:18 AM, Mike Meyer <[email protected]> wrote:
> 
>> ghc can't decide whether or not the tests in the guards are complete or 
>> not.
> 
> Expanding on this: that < and >= cover all cases is something that is 
> convention for Ord instances, not something absolutely guaranteed to be
> true. (In fact, they *don't* cover all cases for IEEE floating point math, 
> if either value is NaN. An SQL numeric value type would also not
> cover all cases because of the behavior of NULL. In both those cases, *both* 
> conditions would return False.) The fact that you specified a
> type for which it does happen to be true doesn't really matter, because 
> there's no way to convey a proof to the compiler that it's true for
> some types but not others. (Some argue that this and some other things are 
> signs that the Ord typeclass is poorly designed; that is a fairly
> complex discussion.)

Interesting! This got me thinking - is this issue because the compiler 
doesn't (cannot?) see the implementation of e.g. (<=)?

I noticed that a similiar case exists with

   f :: Bool -> Bool
   f x | x = True
       | not x = False

...which yields the same warning. I suppose this is because the compiler 
doesn't know the definition of 'not' so it doesn't understand that either of 
the two guards will always be True.

Is there some technical reason for this - maybe it's very time consuming 
prove that the guards are exhaustive?

-- 
Frerich Raabe - [email protected]
www.froglogic.com - Multi-Platform GUI Testing


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

Message: 6
Date: Tue, 10 Feb 2015 23:46:26 +0700
From: Kim-Ee Yeoh <[email protected]>
To: "[email protected]" <[email protected]>
Subject: [Haskell-beginners] Fwd: GHC 7.10 Prelude: we need your
        opinion
Message-ID:
        <capy+zdrhdmctsqnypwol3kjh9tjaj1w7hx6w769w7vcqymh...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Simon PJ missed out the haskell-beginners list, but I encourage you to fill
out the survey below as well.

Now you may ask, "Well, I'm still learning haskell and I don't know enough."

But consider that by being on this list and by haskelling whatever you may
consider as utterly insignificant, you're still waaaaaaaay ahead than those
who have yet to reach haskell at all.

Your opinion counts.

Because those _after_ you will help provide jobs by creating haskell
projects, just like you.

But unlike them, you get to influence the haskell of tomorrow that will be
their first encounter, whether that would be a haskell that's friendlier or
more @#$%^& than what it is today.

The survey link is here:
*http://goo.gl/forms/XP1W2JdfpX <http://goo.gl/forms/XP1W2JdfpX>*

Summaries (each quite long) are here:

?         Overall summary: https://ghc.haskell.org/trac/ghc/wiki/Prelude710
<https://www.google.com/url?q=https%3A%2F%2Fghc.haskell.org%2Ftrac%2Fghc%2Fwiki%2FPrelude710&sa=D&sntz=1&usg=AFQjCNE1p5w-YCXC7ixebvwObayuV7Ut4w>

?         Details of Plan List:
https://ghc.haskell.org/trac/ghc/wiki/Prelude710/List
<https://www.google.com/url?q=https%3A%2F%2Fghc.haskell.org%2Ftrac%2Fghc%2Fwiki%2FPrelude710%2FList&sa=D&sntz=1&usg=AFQjCNHaufeSwtIsvZwdVXwP9F9G45zLSA>
?         Details of Plan FTP:
https://ghc.haskell.org/trac/ghc/wiki/Prelude710/FTP
<https://www.google.com/url?q=https%3A%2F%2Fghc.haskell.org%2Ftrac%2Fghc%2Fwiki%2FPrelude710%2FFTP&sa=D&sntz=1&usg=AFQjCNHbhNyIwAbcOd3JfikIhD6S7rc-vw>

Fwiw, I voted to delay FTP. In fact, here's what I wrote:

"FTP is rushed and potentially unstable. I don't think we understand all
about Traversable that we think we do, which might mean another big Prelude
overhaul in the future.

Actually, FTP doesn't even belong in 7.12 per se. It belongs in a new
Haskell language standard and if that coincides with GHC 7.12, great. If
not, it can wait for GHC 8.x and up."

Because I've been keeping tabs on FTP I wrote my opinion without perusing
the summaries, but on doing so later, I stumbled upon the following points
that happen to reflect my exact observations, points that are relevant to
learning haskell and growing the haskell community:

https://ghc.haskell.org/trac/ghc/wiki/Prelude710/List


   - The existing corpus of books, tutorials, syllabi, and the like usually
   have a significant portion of the text dedicated to these very Prelude
   functions - and they would all need significant revision.


   - Teaching beginners what sequence means in its full generality is going
   to be a challenge.


   - While teaching beginners who end up on #haskell IRC might be possible,
   this is likely to increase the "bounce" rate, people who see Haskell, play
   around, and run away scared. I think Haskell probably has a higher bounce
   rate than most other languages, making it worse would be bad.


Whether you agree or disagree with the above, now's the time to make
yourself heard. The survey closes Feb 21.

p.s. Needless to say, feel free to discuss FTP on this list should your
opinion need a sounding board and a bit of time (not too long!) to firm up.

-- Kim-Ee

---------- Forwarded message ----------
From: Simon Peyton Jones <[email protected]>
Date: Tue, Feb 10, 2015 at 10:50 PM
Subject: GHC 7.10 Prelude: we need your opinion
To: "[email protected]" <[email protected]>, "Haskell Cafe (
[email protected])" <[email protected]>, GHC users <
[email protected]>, "[email protected]" <
[email protected]>


 Haskell Friends

*This email asks for your help in deciding how to proceed with some Prelude
changes in GHC 7.10.  Please read on, but all the info is also at the
survey link, here: http://goo.gl/forms/XP1W2JdfpX
<http://goo.gl/forms/XP1W2JdfpX>.   Deadline is 21 Feb.*



The ?Core Libraries Committee (CLC) is responsible for developing the core
libraries that ship with GHC. This is an important but painstaking task,
and we owe the CLC a big vote of thanks for taking it on.

For over a year the CLC has been working on integrating the *Foldable and
Traversable classes* (shipped in base in GHC 7.8) into the core libraries,
and into the Prelude in particular. Detailed planning for GHC 7.10 started
in the autumn of 2014, and the CLC went ahead with this integration.

Then we had a failure of communication.  As these changes affect the
Prelude, which is in scope for all users of Haskell, these changes should
be held to a higher bar than the regular libraries@ review process.
However, the Foldable/Traversable changes were not particularly well
signposted. Many people have only recently woken up to them, and some have
objected (both in principle and detail).

This is an extremely unfortunate situation. On the one hand we are at RC2
for GHC 7.10, so library authors have invested effort in updating their
libraries to the new Prelude. On the other, altering the Prelude is in
effect altering the language, something we take pretty seriously. We should
have had this debate back in 2014, but here we are, and it is unproductive
to argue about whose fault it is. We all share responsibility.

We need to decide what to do now. A small group of us met by Skype and
we've decided to do this:

?         Push back GHC 7.10's release by at least a month, to late March.
This delay also gives us breathing space to address an unrelated
show-stopping bug, Trac #9858.

?         Invite input from the Haskell community on which of two
approaches to adopt (this survey <http://goo.gl/forms/XP1W2JdfpX>).  The
main questions revolve around impact on the Haskell ecosystem (commercial
applications, teaching, libraries, etc etc), so we want to ask your opinion
rather than guess it.

?         Ask Simon Marlow and Simon Peyton Jones to decide which approach
to follow for GHC 7.10.

Wiki pages have been created summarizing these two primary alternatives,
including many more points and counter-points and technical details:

?         Overall summary: https://ghc.haskell.org/trac/ghc/wiki/Prelude710
<https://www.google.com/url?q=https%3A%2F%2Fghc.haskell.org%2Ftrac%2Fghc%2Fwiki%2FPrelude710&sa=D&sntz=1&usg=AFQjCNE1p5w-YCXC7ixebvwObayuV7Ut4w>

?         Details of Plan List:
https://ghc.haskell.org/trac/ghc/wiki/Prelude710/List
<https://www.google.com/url?q=https%3A%2F%2Fghc.haskell.org%2Ftrac%2Fghc%2Fwiki%2FPrelude710%2FList&sa=D&sntz=1&usg=AFQjCNHaufeSwtIsvZwdVXwP9F9G45zLSA>

?         Details of Plan FTP:
https://ghc.haskell.org/trac/ghc/wiki/Prelude710/FTP
<https://www.google.com/url?q=https%3A%2F%2Fghc.haskell.org%2Ftrac%2Fghc%2Fwiki%2FPrelude710%2FFTP&sa=D&sntz=1&usg=AFQjCNHbhNyIwAbcOd3JfikIhD6S7rc-vw>

This survey invites your input on which plan we should follow. Would you
please

?         Read the details of the alternative plans on the three wiki pages
above

?         Add your response to the survey <http://goo.gl/forms/XP1W2JdfpX>

Please do read the background.  Well-informed responses will help.  Thank
you!

*DEADLINE: 21 February 2015*

Simon PJ

_______________________________________________
ghc-devs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/ghc-devs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20150210/8b83ce31/attachment.html>

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

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


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

End of Beginners Digest, Vol 80, Issue 18
*****************************************

Reply via email to