[GHC] #1749: forall type gives "not polymorphic enough" error incorrectly

GHC trac at haskell.org
Sat Sep 29 17:31:02 EDT 2007


#1749: forall type gives "not polymorphic enough" error incorrectly
----------------------------------------+-----------------------------------
    Reporter:  guest                    |        Owner:         
        Type:  bug                      |       Status:  closed 
    Priority:  normal                   |    Milestone:         
   Component:  Compiler (Type checker)  |      Version:  6.6.1  
    Severity:  normal                   |   Resolution:  invalid
    Keywords:                           |   Difficulty:  Unknown
          Os:  Windows                  |     Testcase:         
Architecture:  x86                      |  
----------------------------------------+-----------------------------------
Changes (by guest):

 * cc: ryani.spam at gmail.com (added)

Comment:

 Replying to [comment:3 simonpj]:
 > Meanwhile, your best bet is a type signature, only you can do it a bit
 less clumsily using a `forall` to bring the type variables into scope
 {{{
 sfPure2 :: forall b c. (b -> c) -> SF b c
 sfPure2 f = SF sf where
      sf :: forall s. ST s (SFST s b c)
      sf = return $ \b -> return (f b)
 }}}

 Interesting.  Giving "sf" a type signature was my first idea, so I
 probably subconciously realized it was MR-related, but it didn't work
 because b & c weren't in scope.  Up until now I believed that these two
 type signatures are equivalent:
 {{{
 sfPure :: (b -> c) -> SF b c
 sfPure2 :: forall b c. (b -> c) -> SF b c
 }}}

 Is there a reason why the former doesn't scope in b & c but the latter
 does?  Actually, I think I see why; the forall limits the lexical scope to
 the internals of the function, whereas without that you can't immediately
 tell whether b & c are captured from the higher level environment or are
 "fresh" type variables to be brought into scope.

 Thanks!

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/1749#comment:4>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the Glasgow-haskell-bugs mailing list