#2418: desugaring type function application to constraint makes bug disappear
------------------------------+---------------------------------------------
    Reporter:  claus          |       Owner:                         
        Type:  bug            |      Status:  new                    
    Priority:  normal         |   Component:  Compiler (Type checker)
     Version:  6.9            |    Severity:  normal                 
    Keywords:  type families  |    Testcase:                         
Architecture:  Unknown        |          Os:  Unknown                
------------------------------+---------------------------------------------
 When considering type functions, I find it helpful to desugar their
 applications into additional constraints (`tf a` becomes `tf a~tfa=>tfa`).
 But consider this example from a recent [http://www.haskell.org/pipermail
 /haskell-cafe/2008-July/044911.html haskell-cafe thread]:
 {{{
 {-# OPTIONS_GHC -fglasgow-exts #-}

 class Blah f a where blah :: a -> T f f a
 class A f where type T f :: (* -> *) -> * -> *

 -- wrapper :: forall a f tf . (Blah f a,T f~tf) => a -> tf f a
 wrapper :: forall a f . (Blah f a) => a -> T f f a
 wrapper x = blah x
 }}}
 for which `GHCi, version 6.9.20080514` yields:
 {{{
 C:\Documents and Settings\cr3\Desktop\TF.hs:8:12:
     Could not deduce (Blah f a) from the context (Blah f1 a)
       arising from a use of `blah'
                    at C:\Documents and Settings\cr3\Desktop\TF.hs:8:12-17
     Possible fix:
       add (Blah f a) to the context of the type signature for `wrapper'
     In the expression: blah x
     In the definition of `wrapper': wrapper x = blah x

 C:\Documents and Settings\cr3\Desktop\TF.hs:8:12:
     Couldn't match expected type `T f1 f1 a'
            against inferred type `T f f a'
     In the expression: blah x
     In the definition of `wrapper': wrapper x = blah x
 Failed, modules loaded: none.
 }}}
 Switching to the desugared version of the `wrapper` signature makes the
 error go away, so the "desugared" and original version are not equivalent
 in the current implementation of type families! See also
 [http://www.haskell.org/pipermail/haskell-cafe/2008-July/044914.html].

 For added fun, GHCi reports the sugared type when using the desugared one:
 {{{
 *Main> :t wrapper
 wrapper :: (Blah f a) => a -> T f f a
 }}}

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/2418>
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