# GHC.Exe Panic (The 'Impossible' happened)

Reported by: Owned by: ColonelTrick normal Compiler 8.0.2 Unknown/Multiple Unknown/Multiple None/Unknown #13106

### Description

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
```

### comment:1 Changed 19 months ago by RyanGlScott

Related Tickets: → #13106 → duplicate new → closed 8.2.1 → 8.0.2

Thanks for the bug report. This is a duplicate of #13106, which has been fixed in GHC 8.2.1. (On GHC 8.2.1, it would give a proper error that `n` is out of scope in the definition of `validate`.)

Note: See TracTickets for help on using tickets.