什么是多态类型的用法? [英] What are uses of polymorphic kinds?

查看:180
本文介绍了什么是多态类型的用法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

多态类型是Haskell类型系统的扩展,支持 by UHC,允许

Polymorphic kinds are an extension to Haskell's type system, supported by UHC, allowing

data A x y = A (y x)

键入(kinded?)为 a - > (a - > *) - > * 。它们有什么用处?

to be typed (kinded?) as a -> (a -> *) -> *. What are they useful for?

推荐答案

一个可能的用法示例可以使用conal的 TypeCompose 以无点式创作monad变形金刚。

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

(就像一个例子,我不知道用这些foos来做什么,酒吧..)

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

(除了 newtype -wrappers)

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

这篇关于什么是多态类型的用法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆