Skip to content

GHC.Exe Panic (The 'Impossible' happened)

Unfortunately, I am just learning Haskell, so I do not have the context to narrow this down to a narrow repro.

Console Output:

PS C:\Haskell> ghc -o creditCard .\CreditCards.hs [1 of 1] Compiling Main ( CreditCards.hs, Credit ghc.exe: panic! (the 'impossible' happened)

(GHC version 8.0.2 for x86_64-unknown-mingw32):

initTc: unsolved constraints WC {wc_insol = [W] n_a1PN :: t_a1PM[tau:1] (CHoleCan: n)}

CreditCards.hs

-- Converts a number to digits
toDigits :: Integer -> [Integer]

toDigits n
  | n <= 0 = []
  | otherwise = n `mod` 10 : toDigits (n `div` 10)

-- Converts a number to digits and then reverses it
toDigitsRev :: Integer -> [Integer]
toDigitsRev n = reverse . toDigits n

-- Doubles every other value
doubleEveryOther :: [Integer] -> [Integer]

doubleEveryOther[] = []
doubleEveryOther ([x:[]]) = [x]
doubleEveryOther (x : y : zs) = x : 2 * y : doubleEveryOther zs 

-- Sums the digits of the credit card.
sumDigits :: [Integer] -> [Integer]

sumDigits [] = 0
sumDigits (x:xs)
  | x < 10 = x + sumDigits xs
  | otherwise = (x `mod` 10) + (x `div` 10) + sumDigits xs

--- Inidicates whether the credit card is valid.
validate :: [Integer] -> Bool

validate x =  (sumDigits (doubleEveryOther (toDigitsRev n)) `mod` 10) == 0
Trac metadata
Trac field Value
Version 8.2.1
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