[Haskell-cafe] Annoying problem when pattern matching negative integer literals and wildcards
ietf-dane at dukhovni.org
Fri Mar 15 04:47:44 UTC 2019
On Thu, Mar 14, 2019 at 10:54:58PM -0500, Vanessa McHale wrote:
> encryptionResult :: Int -> EncryptionResult
> encryptionResult 1 = HasEncryption
> encryptionResult -1 = EncryptionUnknown
> encryptionResult _ = error "Internal error."
The way I keep it straight, is that just as one must write:
let x = encryptionResult (-1)
to evaluate "encryptionResult" at (-1), one must also write:
encryptionResult :: Int -> EncryptionResult
encryptionResult 1 = HasEncryption
encryptionResult (-1) = EncryptionUnknown
encryptionResult _ = error "Internal error."
to define the function, because binary minus takes precedence over
unary minus (which in turn takes precedence over sections, thus
(subtract 1), not (- 1)).
More information about the Haskell-Cafe