[GHC] #11473: Levity polymorphism checks are inadequate

GHC ghc-devs at haskell.org
Thu Jan 21 12:17:52 UTC 2016


#11473: Levity polymorphism checks are inadequate
-------------------------------------+-------------------------------------
           Reporter:  simonpj        |             Owner:
               Type:  bug            |            Status:  new
           Priority:  normal         |         Milestone:
          Component:  Compiler       |           Version:  7.10.3
           Keywords:                 |  Operating System:  Unknown/Multiple
  LevityPolymorphism                 |
       Architecture:                 |   Type of failure:  None/Unknown
  Unknown/Multiple                   |
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 Ben found
 {{{
 {-# LANGUAGE PolyKinds, TypeFamilies, MagicHash, DataKinds, TypeInType,
 RankNTypes #-}

 import GHC.Exts
 import GHC.Types

 type family Boxed (a :: k) :: *
 type instance Boxed Char# = Char
 type instance Boxed Char  = Char

 class BoxIt (a :: TYPE lev) where
     boxed :: a -> Boxed a

 instance BoxIt Char# where boxed x = C# x
 instance BoxIt Char  where boxed = id

 hello :: forall (lev :: Levity). forall (a :: TYPE lev). BoxIt a => a ->
 Boxed a
 hello x = boxed x
 {-# NOINLINE hello #-}

 main :: IO ()
 main = do
     print $ boxed 'c'#
     print $ boxed 'c'
     print $ hello 'c'
     print $ hello 'c'#
 }}}
 This is plainly wrong because we have a polymorphic function `boxed` that
 is being passed both boxed and unboxed arguments.

 You do get a Lint error with `-dcore-lint`.

 But the original problem is with the type signature for `boxed`.  We
 should never have a levity-polymorphic type to the left of an arrow.  To
 the right yes, but to the left no.   I suppose we could check that in
 `TcValidity`.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11473>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list