简体   繁体   English

多态类型有什么用途?

[英]What are uses of polymorphic kinds?

Polymorphic kinds are an extension to Haskell's type system, supported by UHC, allowing 多态类型是Haskell类型系统的扩展,由UHC 支持 ,允许

data A x y = A (y x)

to be typed (kinded?) as a -> (a -> *) -> * . 键入(kinded?)为a -> (a -> *) -> * (a- a -> (a -> *) -> * What are they useful for? 它们有什么用?

One possible usage example can be using conal's TypeCompose for composing monad transformers in point-free style. 一个可能的用法示例是使用圆锥形TypeCompose组成无点样式的monad变压器。

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..) (仅作为示例,我不知道这些foo和bar会做什么。。)

Instead of: 代替:

type MyT m = StateT Foo (MaybeT (ContT Bar m))

(this would have the same result apart from newtype -wrappers) (这将具有相同的结果除了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 在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 . 也就是说,向Haskell添加多态类型的总体原因是为了改善类型级别编程的体验。 Currently type level programming in Haskell proceeds in a essentially untyped " kind " level. 当前,Haskell中的类型级别编程以基本上没有类型的“ 种类 ”级别进行。 A richer kind language will make type level programming in Haskell, in general, easier. 通常,更丰富的一种语言将使在Haskell中进行类型级别的编程更加容易。

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.. 一个更具体的示例是从SYB样式的泛型( 引用 )中删除(动态)可类型化约束,并改善对更高种类的泛型编程的总体支持。

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(). 一个具体的示例可能是一个函数,该函数给定具有任意Arity的数据构造函数,然后返回一个将给定构造函数包装在Some()中的新数据构造函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM