Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are uses of polymorphic kinds?

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?

like image 659
sdcvvc Avatar asked Jun 17 '10 12:06

sdcvvc


People also ask

What are the uses of polymorphism?

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.

What is the most common use of polymorphism?

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.

What is an example of a 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.

What is a polymorphic application?

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.


2 Answers

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.

like image 156
yairchu Avatar answered Sep 28 '22 16:09

yairchu


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..

like image 21
Don Stewart Avatar answered Sep 28 '22 15:09

Don Stewart