Polymorphic kinds are an extension to Haskell's type system, supported by UHC, allowing
data A x y = A (y x)
to be typed (kinded?) as a -> (a -> *) -> *
. What are they useful for?
Polymorphism allows us to perform a single action in different ways. In other words, polymorphism allows you to define one interface and have multiple implementations. The word “poly” means many and “morphs” means forms, So it means many forms.
The most common use of polymorphism in OOP occurs when a parent class reference is used to refer to a child class object. Any Java object that can pass more than one IS-A test is considered to be polymorphic.
A real-life example of polymorphism is a person who at the same time can have different characteristics. Like a man at the same time is a father, a husband and an employee. So the same person exhibits different behavior in different situations. This is called polymorphism.
Polymorphism is a feature of object-oriented programming languages that allows a specific routine to use variables of different types at different times. Polymorphism is the ability of a programming language to present the same interface for several different underlying data types.
One possible usage example can be using conal's TypeCompose for composing monad transformers in point-free style.
type MyT = StateT Foo :. MaybeT :. ContT Bar
(just as an example, I have no idea what one's going to do with those foos and bars..)
Instead of:
type MyT m = StateT Foo (MaybeT (ContT Bar m))
(this would have the same result apart from newtype
-wrappers)
Currently you'll need to duplicate the combinators code for different kinds, and this extension abolishes the repetition and allows using one piece of code to rule them all.
Adding Polymorphic Kinds to GHC
The background to this question would be the motivation in general for a more expressive kind system.
That is, the overall reason to add polymorphic kinds to Haskell is to improve the experience of type level programming. Currently type level programming in Haskell proceeds in a essentially untyped "kind" level. A richer kind language will make type level programming in Haskell, in general, easier.
A more concrete example would be to remove the (dynamic) Typeable constraint from generics of the SYB style (citation), as well as improving overall support for higher-kinded generic programming..
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