Skip to content

ghc: panic! (the 'impossible' happened), initTc: unsolved constraints

NB! I'm no expert on the compiler and have not used GHC/GHCi very much. I have istaller the Haskell Platform and then run GHCi from within Aquamacs (emacs) using tthe Haskell mode already available there. I should say that everything worked fine and I could both load and run code. But then this happend when I started with the type Char and the functions ord and chr, so maybe the error has to do with them(?) Please change the subject to something relevant; I really have no clue what has happened here. Just like to help. /Håkan

This is the error message:

GHCi, version 8.0.2: http://www.haskell.org/ghc/  :? for help
Prelude> :load "/Users/hj/Downloads/d7012e-vt17/test.hs"
[1 of 1] Compiling Main             ( /Users/hj/Downloads/d7012e-vt17/test.hs, interpreted )
ghc: panic! (the 'impossible' happened)
  (GHC version 8.0.2 for x86_64-apple-darwin):
	initTc: unsolved constraints
  WC {wc_insol = [W] –_a2n2 :: t_a2n1[tau:1] (CHoleCan: –)}

Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

> 

This is my Haskell code (putting together examples for a first lecture on declarative languages/functional languages):

module Main (main) where
import Data.Char (ord,chr)

square :: Int -> Int
square n = n * n

primes :: [Int]
primes = filterPrime [2..]
  where
    filterPrime (p:xs) =
       p : filterPrime [x | x <- xs, x `mod` p /= 0]

-- take :: Int -> [a] -> [a]

double :: Int -> Int
double n = 2*n

dubSq1 :: Int -> Int
dubSq1 n = double (square n)

dubSq2 :: Int -> Int
dubSq2 = double . square

-- Bool

nAnd :: Bool -> Bool -> Bool
nAnd x y = not (x && y)

nAnd2 :: Bool -> Bool -> Bool
nAnd2 True True = False
nAnd2 False False = False
nAnd2 x y = True

-- if, the, else

max2 :: Int -> Int -> Int
max2 x y = 
  if x >= y then x else y

-- Int

max3 :: Int -> Int -> Int -> Int
max3 a b c = max2 (max2 a b) c

f :: Int -> Int
f 1 = 0
f n = if  n `mod` 2 == 0 then n `div` 2 else 3*n + 1



isDigit :: Char -> Bool
isDigit ch = ('0' <= ch) && (ch <= '9')

isLower :: Char -> Bool
isLower ch = ('a' <= ch) && (ch <= 'z') -- no åäö in ASCII

offset :: Int
offset = ord 'A'  ord 'a'

toUpper :: Char -> Char
toUpper ch = chr (ord ch + offset)








f' 1 = 0
f' n
  | n `mod` 2 == 0 = n `div` 2
  | otherwise = 3*n + 1

life_length x
  | x == 1 = 0
  | otherwise = 1 + life_length(f' x)
Edited by Ryan Scott
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information