
Ah nevermind, I figured it out: the second bit was being treated as a definition for (-) On 3/14/19 10:54 PM, Vanessa McHale wrote:
I have the following program:
module Bug ( encryptionResult ) where
data EncryptionResult = HasEncryption | EncryptionUnknown
encryptionResult :: Int -> EncryptionResult encryptionResult 1 = HasEncryption encryptionResult -1 = EncryptionUnknown encryptionResult _ = error "Internal error."
When I try to compile it with GHC I get
[1 of 1] Compiling Bug ( Bug.hs, Bug.o )
Bug.hs:9:1: error: Multiple declarations of ‘encryptionResult’ Declared at: Bug.hs:7:1 Bug.hs:9:1 | 9 | encryptionResult _ = error "Internal error." | ^^^^^^^^^^^^^^^^
I can replicate this in Hugs, viz.
ERROR "Bug.hs":7 - "encryptionResult" multiply defined
However, everything compiles fine when I write
module Bug ( encryptionResult ) where
data EncryptionResult = HasEncryption | EncryptionUnknown
encryptionResult :: Int -> EncryptionResult encryptionResult 1 = HasEncryption encryptionResult -1 = EncryptionUnknown
or
module Bug ( encryptionResult ) where
data EncryptionResult = HasEncryption | EncryptionUnknown
encryptionResult :: Int -> EncryptionResult encryptionResult 1 = HasEncryption encryptionResult 0 = EncryptionUnknown encryptionResult _ = error "Internal error."
Am I doing something obviously screwy? This seems like a pretty annoying feature on the language (to the point where I assumed it was a GHC bug until I got the same behavior with Hugs) and I can't figure out why it exists.
Cheers, Vanessa McHale