Skip to content

Non-local bug reporting around levity polymorphism

From ticket:13105#comment:141886.

In HEAD (or, at least, my version, on the wip/rae branch), this code

class Unbox (t :: *) (r :: TYPE k) | t -> r, r -> t where
  unbox :: t -> r
  box :: r -> t
  
instance Unbox Int Int# where
  unbox (I# i) = i
  box i = I# i

instance Unbox Char Char# where
  unbox (C# c) = c
  box c = C# c

instance (Unbox a a', Unbox b b') => Unbox (a,b) (# a', b' #) where
  unbox (a,b) = (# unbox a, unbox b #)
  box (# a, b #) = (box a, box b)

testInt :: Int
testInt = box (unbox 1)

testTup :: (Int, Char)
testTup = box (unbox (1, 'a'))

fails with

Bug.hs:27:11: error:
    • Couldn't match a lifted type with an unlifted type
      When matching types
        a' :: *
        Int# :: TYPE 'IntRep
    • In the expression: box (unbox 1)
      In an equation for ‘testInt’: testInt = box (unbox 1)
   |
27 | testInt = box (unbox 1)
   |           ^^^^^^^^^^^^^

Bug.hs:27:16: error:
    • Couldn't match a lifted type with an unlifted type
      When matching types
        a' :: *
        Int# :: TYPE 'IntRep
    • In the first argument of ‘box’, namely ‘(unbox 1)’
      In the expression: box (unbox 1)
      In an equation for ‘testInt’: testInt = box (unbox 1)
   |
27 | testInt = box (unbox 1)
   |                ^^^^^^^

Bug.hs:42:11: error:
    • Couldn't match a lifted type with an unlifted type
      When matching types
        a' :: *
        Int# :: TYPE 'IntRep
    • In the expression: box (unbox (1, 'a'))
      In an equation for ‘testTup’: testTup = box (unbox (1, 'a'))
   |
42 | testTup = box (unbox (1, 'a'))
   |           ^^^^^^^^^^^^^^^^^^^^

I think it should succeed. Worse, when I comment out the testTup definition, the file succeeds... but note that two of the errors above are in testInt, which compiles fine on its own.

Trac metadata
Trac field Value
Version 8.3
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information