On 4/4/11 7:21 PM, Sandro Magi wrote:
> On 04/04/2011 2:21 AM, Jonathan S. Shapiro wrote:
>> Second, it's important to note that no current language defines any
>> interface notion on structs (as opposed to classes). This means that an
>> interface object, and the class instance that it wraps, are reference
>> types. This has *huge* implications for compilation.
>
> Haskell supports unboxed types, but I'm not clear whether this extends
> to type classes. If it doesn't, this would be an artificial limitation,
> not an intrinsic one. The same representation issues are at work in any
> OO/interface abstraction you're going to introduce.

Consider,

     {-# LANGUAGE MagicHash #-}
     module UnboxedClass where

     -- The type Int# is an unboxed arch-sized integer
     import GHC.Prim (Int#)

     -- data Int = I# Int#
     import GHC.Types (Int(I#))

     class UnboxedClass a where
         foo :: Int# -> a

     instance UnboxedClass Int where
         foo = I#

     instance UnboxedClass Int# where
         foo = id

When loading/compiling, you get the error:

     Expecting a lifted type, but `Int#' is unlifted
     The first argument of `UnboxedClass' should have kind `*',
     but `Int#' has kind `#'
     In the instance declaration for `UnboxedClass Int#'

Which is to say that unboxed types cannot be parameters to a type class, 
though they're perfectly fine to use within a class (note that the 
UnboxedClass Int instance is accepted just fine).

This is an artificial restriction, as you say. It has to do with the 
hackish way that GHC supports unboxed types by introducing a sub-kinding 
relation in the kind system. In particular, there's no syntactic support 
for talking about kinds other than `*'[1], so there's no way to say that 
the type-class parameter is allowed to be of kind `?' (== either `*' or 
`#')[2].

JHC has a much more complicated kinding system since it does a lot of 
work on unboxing and similar transformations (far more than GHC does). I 
don't know if they've investigated lifting this restriction or not, but 
that'd be the place to look.


[1] and `*->*', `*->*->*',  `(*->*)->*',... naturally.

[2] Or maybe I mean kind `??'. One of them includes the so-called 
unboxed tuples (i.e., all components are passed in registers), whereas 
the other doesn't. I forget which is which, and my google-fu is failing me.

-- 
Live well,
~wren
_______________________________________________
bitc-dev mailing list
[email protected]
http://www.coyotos.org/mailman/listinfo/bitc-dev

Reply via email to