GHC type-checker bug

Iavor S. Diatchki diatchki at cse.ogi.edu
Thu Sep 23 06:30:20 EDT 2004


Hello,
The following program:

 > f :: (forall a. Eq a => [a]) -> Bool
 > f xs@(x:_)  = x
 >
 > main = main

Causes ghc to report the following:

ghc-6.2.1: panic! (the `impossible' happened, GHC version 6.2.1):
        cgPanic
    zddEq {- v a9y -}
    static binds for:
    local binds for:
    Main.main {- v r2X -}
    SRT labelghc-6.2.1: panic! (the `impossible' happened, GHC version 
6.2.1):
        initC: srt

Please report it as a compiler bug to glasgow-haskell-bugs at haskell.org,
or http://sourceforge.net/projects/ghc/.

I was surprised that GHC allows pattern matching on things that are of a 
qualified
type, as I think of such things as functions, and if something is Nil or 
Cons could depend
on the type at which it is used (i.e. the dictionary argument).   From 
my experiments
it seems that GHC decides what dictionary to pass based on the types of 
the subpatterns
(and reports an ambiguity if this type cannot be determined).  Is that 
the intended meaning?

There seem to be some other problems with this feature too, for example 
if I change the definition for 'f' to:

 > f [x] = x

I get the following error:
test1.hs:5:
    Couldn't match `forall a. (Eq a) => [a]' against `[t]'
        Expected type: forall a. (Eq a) => [a]
        Inferred type: [t]
    When checking the pattern: [x]
    In the definition of `f': f [x] = x

However if I rewrite this to what I thought was equivalent:

 > f (x:[]) = x

ghc accepts the program without a complaint.

I realize that hardly anyone writes such programs, I only thought of them
because I was wondering if they make sense in the context of my own type 
checker.

-iavor






More information about the Glasgow-haskell-bugs mailing list