[ghc] kind of the function arrow

I was just playing around and noticed that the kind of the function arrow in GHC is (?? -> ? -> *) when I (naively) expected it to be (* -> * -> *). After looking at (http://hackage.haskell.org/packages/archive/ghc/6.10.2/doc/html/Type.html#5) I see that the kind of (->) means that the parameter type cannot be an unboxed tuple, whilst the result type can be anything. Why is this? After reading this documentation I would expect the kind (? -> ? -> *). I'm now wondering if the kind of (->) could cause problems if the following style of declaration is requried:
type FunArg a b = (a -> b, a)
*Main> :k FunArg FunArg :: * -> * -> * By using type variables, whose default kind is *, the function type is fixed to use only boxed types. But if one wanted to allow unboxed type parameters the kind would be wrong, and an explicit kind signature of # or ? can't be given as they are not part of Haskell's source language. I guess my question is why the (?? -> ? -> *) kind on (->) and what to do if synonyms or data types over (->) are required such as the example just stated. I'm just curious. Thanks, Dominic

Dominic Orchard wrote:
I was just playing around and noticed that the kind of the function arrow in GHC is (?? -> ? -> *) when I (naively) expected it to be (* -> * -> *). After looking at (http://hackage.haskell.org/packages/archive/ghc/6.10.2/doc/html/Type.html#5) I see that the kind of (->) means that the parameter type cannot be an unboxed tuple, whilst the result type can be anything. Why is this? After reading this documentation I would expect the kind (? -> ? -> *).
Unboxed tuples don't exist. That is, they are in evidence, but they don't actually have any physical representation. The elements of an unboxed tuple are stored in registers when returning from a function, so that the caller can access them immediately (rather than needing to indirect through a pointer to a tuple). ISTR that because of this strategy, there are restrictions on what types of tuples can be unboxed. Theoretically GHC could also allow passing certain arguments in registers when invoking a function, but this isn't supported as yet. -- Live well, ~wren
participants (2)
-
Dominic Orchard
-
wren ng thornton