What are uses of polymorphic kinds?

青春壹個敷衍的年華 提交于 2020-01-01 04:17:48

问题


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?


回答1:


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.




回答2:


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




回答3:


They are useful for defining functions that operate over data constructors with arbitrary arity, of course!

A concrete example could be a function that, given a data constructor with arbitrary arity, returns a new data constructor that wraps the given constructor in Some().



来源:https://stackoverflow.com/questions/3061428/what-are-uses-of-polymorphic-kinds

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!