[GHC] #13105: Allow type families in RuntimeReps

GHC ghc-devs at haskell.org
Mon Sep 4 12:28:22 UTC 2017


#13105: Allow type families in RuntimeReps
-------------------------------------+-------------------------------------
        Reporter:  goldfire          |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  8.0.1
      Resolution:                    |             Keywords:
                                     |  LevityPolymorphism
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
                                     |  typecheck/should_fail/T13105
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by magesh.b):

 {{{#!haskell

 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)

 -- Works fine
 testInt :: Int
 testInt = box (unbox 1)

 -- Throws an error at call site
 {-error:
 • Couldn't match a lifted type with an unlifted type
       When matching the kind of ‘Int#’
     • In the expression: box (unbox (1, 'a'))
       In an equation for ‘testTup’: testTup = box (unbox (1, 'a'))
     |
 168 | testTup = box (unbox (1, 'a'))
     |           ^^^^^^^^^^^^^^^^^^^^
 -}


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

 }}}

 Does this error related to same bug?

 Any chance of such code to work in future GHC release or is it
 fundamentally not possible to have a levity polymorphic class as a
 constraint in an instance declaration.

 One of the use case is, above code would have allowed me to pack user
 defined data type in to highly packed unboxed anonymous record (using
 nested Unboxed Tuple) making boxing/unboxing first class in GHC.

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


More information about the ghc-tickets mailing list