#5012: haskell 98 program does not typecheck when compiled with -XTypeFamilies
---------------------------------------+------------------------------------
 Reporter:  jcpetruzza                 |          Owner:                        
 
     Type:  bug                        |         Status:  closed                
 
 Priority:  normal                     |      Component:  Compiler (Type 
checker)
  Version:  7.0.2                      |     Resolution:  invalid               
 
 Keywords:                             |       Testcase:                        
 
Blockedby:                             |             Os:  Unknown/Multiple      
 
 Blocking:                             |   Architecture:  Unknown/Multiple      
 
  Failure:  GHC rejects valid program  |  
---------------------------------------+------------------------------------
Changes (by HolgerReinhardt):

  * status:  new => closed
  * resolution:  => invalid


Comment:

 This is caused by a change in the type-checker in GHC 7:
 http://hackage.haskell.org/trac/ghc/blog/LetGeneralisationInGhc7

 This new behaviour gets triggered by activating Type families. The
 solution is to give explicit local type signatures:
 {{{
 {-# OPTIONS -XTypeFamilies -XRankNTypes -XScopedTypeVariables #-}


 f :: forall a m. Monad m => ([m a], [a]) -> m [a]
 f x = do
     a <- apply id     fst
     b <- apply return snd
     return (a ++ b)

  where
     apply :: forall b c. (b -> m c) -> (([m a], [a]) -> [b]) -> m [c]
     apply p r = mapM p (r x)
 }}}

 If you don't want to write the type signatures, you can just make "apply"
 a global function and pass in "x" as a parameter:
 {{{
 f x = do
     a <- apply x id     fst
     b <- apply x return snd
     return (a ++ b)

 apply x p r = mapM p (r x)
 }}}

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