#2360: More information in occurs check message
---------------------------------+------------------------------------------
    Reporter:  ajd               |        Owner:                  
        Type:  feature request   |       Status:  new             
    Priority:  normal            |    Milestone:  6.10 branch     
   Component:  Compiler          |      Version:  6.8.2           
    Severity:  normal            |   Resolution:                  
    Keywords:                    |   Difficulty:  Unknown         
    Testcase:                    |           Os:  Unknown/Multiple
Architecture:  Unknown/Multiple  |  
---------------------------------+------------------------------------------
Changes (by rwbarton):

 * cc: rwbarton (added)

Comment:

 Here are some more interesting cases.  I'm specifically interested in
 whether the error message pinpoints the location of the error; I call
 those error messages good.  My tests are under ghc-6.11.20090107.

 Case 1: A good error message when there's no type signature
 {{{
 Prelude> let m x = x : x in m

 <interactive>:1:14:
     Occurs check: cannot construct the infinite type: a = [a]
       Expected type: [a]
       Inferred type: a
     In the second argument of `(:)', namely `x'
     In the expression: x : x
 }}}

 Case 2: A bad error message when a polymorphic type signature is given
 {{{
 Prelude> let m :: a -> a; m x = x : x in m

 <interactive>:1:17:
     Occurs check: cannot construct the infinite type: a = [a]
     When generalising the type(s) for `m'
     In the expression:
         let
           m :: a -> a
           m x = x : x
         in m
     In the definition of `it':
         it = let
                m :: a -> a
                m x = x : x
              in m
 }}}

 Case 3: A good error when a monomorphic type signature is given
 {{{
 Prelude> let m :: Int -> Int; m x = x : x in m

 <interactive>:1:31:
     Couldn't match expected type `[Int]' against inferred type `Int'
     In the second argument of `(:)', namely `x'
     In the expression: x : x
     In the definition of `m': m x = x : x
 }}}

 The difference between cases 2 and 3 surprises me because I could
 mechanically turn case 2 into case 3 by substituting a fresh type
 constructor for each universally quantified type variable.

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/2360#comment:5>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs

Reply via email to