In this declaration
data Const a = Const Integer
Haskell infers that Const
is * -> *
. Is it possible to make Const
take a type constructor instead, so it will be (* -> *) -> *
? Ideally, it should be a -> *
, but there are no polymorphic kinds. This thread shows one solution - adding unused constructor. Has the situation changed since 2002?
You're right, since GHC doesn't support polymorphic kinds, it will do kind defaulting to *
.
However, using the KindSignatures
extension, you can explicitly annotate a data declaration with a specific kind:
{-# LANGUAGE KindSignatures #-}
data Const (a :: * -> *) = Const Integer
Or, if your a fan of GADTs:
{-# LANGUAGE GADTs #-}
data Const :: (* -> *) -> * where
Const :: Integer -> Const a
You can now write:
x :: Const Maybe
x = Const 2
I just compiled the original program with the experimental Utrecht Haskell Compiler (UHC).
The UHC doesn't really compile any real world programs, but it does support kind polymorphism! Its interesseting to see it infer:
-- kind of data type:
Const :: forall a . a -> *
-- type of constructor:
Const :: Integer -> forall* a . forall b(a) . Const b
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With