Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,842
    • Issues 4,842
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 456
    • Merge requests 456
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
    • Value stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #11245

Closed
Open
Created Dec 17, 2015 by Ömer Sinan Ağacan@osa1Maintainer

Non-exhaustive pattern, "Patterns not matched" list is empty

Example:

module Main where

maybeOdd :: Int -> Maybe Int
maybeOdd i = if odd i then Just i else Nothing

main :: IO ()
main = do
  let x = maybeOdd 10

  let a | Just i <- x
        , odd i
        = True

        | Nothing <- x
        = False

  print x
  print a

Warning printed by GHC HEAD:

Exhaustive.hs:10:7: warning:
    Pattern match(es) are non-exhaustive
    In an equation for ‘a’: Patterns not matched:
Linking Exhaustive ...

The problem with this message is; if it couldn't come up with an example unmatched pattern, then how can it know that the pattern is non-exhaustive? If it came up with an example, why is that example not printed?

UPDATE: I just realized it's actually worse that I first thought. If I change a in this example:

  let a | Just i <- x
        = True

This message is printed:

[1 of 1] Compiling Main             ( Exhaustive.hs, Exhaustive.o )

Exhaustive.hs:10:7: warning:
    Pattern match(es) are non-exhaustive
    In an equation for ‘a’: Patterns not matched:

Exhaustive.hs:10:16: warning: Defined but not used: ‘i’
Linking Exhaustive ...

NOTE: Tried with GHC 7.10 too. It seems like in the case where the checks are not exhaustive, both 7.10 and HEAD are giving the same warning(with empty list of non-checked patterns). HEAD is better in detecting exhaustive patterns.

Trac metadata
Trac field Value
Version 7.11
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking