What are uses of polymorphic kinds?

前端 未结 3 752
走了就别回头了
走了就别回头了 2021-02-13 00:06

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

相关标签:
3条回答
  • 2021-02-13 00:08

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

    0 讨论(0)
  • 2021-02-13 00:10

    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.

    0 讨论(0)
  • 2021-02-13 00:16

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

    0 讨论(0)
提交回复
热议问题