Skip to content

minus in pattern matching context yields unhelpful error message

Motivation

calling ghci Test.hs on a file with this content:

successor :: Double -> Double
successor -5.0e-324 = 0

gives me the following error message:

GHCi, version 8.10.5: https://www.haskell.org/ghc/  :? for help
[1 of 1] Compiling Main             ( Test.hs, interpreted )

Test.hs:1:1: error:
    The type signature for ‘successor’ lacks an accompanying binding
  |
1 | successor :: Double -> Double
  | ^^^^^^^^^
Failed, no modules loaded.

I find this error message rather unhelpful.

Also this function:

f :: Double -> Double
f -1 = 2
f x = 20

has a very unintuitive semantic:

GHCi, version 8.10.5: https://www.haskell.org/ghc/  :? for help
[1 of 1] Compiling Main             ( Test.hs, interpreted )
Ok, one module loaded.
*Main> f (-1)
20.0
*Main> 

Furthermore this file:

f :: Double -> Double
f -1 = 2
f (-1) = 20

g -1 = 0

does not compile with this error message:

GHCi, version 8.10.5: https://www.haskell.org/ghc/  :? for help
[1 of 1] Compiling Main             ( Test.hs, interpreted )

Test.hs:5:3: error:
    Multiple declarations of ‘-’
    Declared at: Test.hs:2:3
                 Test.hs:5:3
  |
5 | g -1 = 0
  |   ^
Failed, no modules loaded.

Proposal

  1. Example: A somehow better error message
  2. Example: An error message instead of accepting the function
  3. Example: Maybe two syntax errors instead of the current error message
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information