有可能“咖喱"吗? Scala中种类更多的类型? [英] Is it possible to "curry" higher-kinded types in Scala?
本文介绍了有可能“咖喱"吗? Scala中种类更多的类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一个具有两个类型参数的特征,例如
Let's suppose I have a trait with two type parameters, e.g.
trait Qux[A, B]
以及具有较高类型参数的另一个特征,例如
and another trait with a higher-kinded type parameter, e.g.
trait Turkle[C[_]]
我希望能够用固定值代替Qux
的类型参数之一,以便可以将其用于参数化Turkle
.
I'd like to be able to substitute a fixed value for one of the type parameters for Qux
, so that it can be used to parametrize Turkle
.
这是一个示例(在Scala中没有意义的代码!):
Here's an example (of code that doesn't make sense in Scala!):
trait Baz[A] extends Turkle[Qux[A, _]]
任何人都知道如何实现这种效果吗?
Anyone have any ideas how to achieve this effect?
推荐答案
Jason Zaugg提出了最简洁的方法:
Jason Zaugg came up with the most succinct way to do this:
trait Baz[A] extends Turkle[({type x[a]=Qux[A, a]})#x]
IntelliJ的Scala插件可以选择将其折叠为:
IntelliJ's Scala plugin will optionally collapse this to:
trait Baz[A] extends Turkle[x[a]=Qux[A, a]]
这篇关于有可能“咖喱"吗? Scala中种类更多的类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文