haskell - How to give a type signature to polymorphic functions when PolyKinds is enabled? -
when enabling polykinds
, valid type signatures can become invalid.
the following code compiles without polykinds
.
{-# language kindsignatures #-} import ghc.generics foo :: constructor c => t c (f :: * -> *) -> [char] foo = conname
when enable polykinds
fails compile.
kind incompatibility when matching types: t0 :: * -> (* -> *) -> * -> * t :: * -> (* -> *) -> k -> * expected type: t c f -> [char] actual type: t0 c f a0 -> [char] relevant bindings include foo :: t c f -> [char] (bound @ gen.hs:8:1) in expression: conname in equation ‘foo’: foo = conname
is there way give type signature foo
when polykinds
enabled?
note discrepancy is
t0 :: * -> (* -> *) -> * -> * t :: * -> (* -> *) -> k -> *
that is, in 1 of signatures ghc thinks third argument of t
should have kind *
, , in other thinks should have polymorphic kind k
.
i think former signature (with *
) comes conname
, while latter k
implicitly comes signature foo
– k
appears because have polykinds
enabled, type signatures interpreted polymorphic kinds when possible. also, design, signature considered give the full "api" function, means no attempt infer kind rest of function done when specify signature explicitly.
in signature third argument of t
type a
, can fix adding kind annotation make consistent conname
wants:
foo :: constructor c => t c (f :: * -> *) (a :: *) -> [char] foo = conname
Comments
Post a Comment