用于 Haskell 中类型表达式的 Lambda?

用于 Haskell 中类型表达式的 Lambda?

问题描述:

Haskell 或特定的编译器是否具有类型级别的 lambda 表达式(如果这甚至是一个术语)?

Does Haskell, or a specific compiler, have anything like type-level lambdas (if that's even a term)?

详细说明,假设我有一个参数化类型 Foo a b 并且希望 Foo _ b 成为 Functor 的一个实例.有没有什么机制可以让我做一些类似于

To elaborate, say I have a parametrized type Foo a b and want Foo _ b to be an instance of, say, Functor. Is there any mechanism that would let me do something akin to

instance Functor (a -> Foo a b) where
...

?

来自 TypeCompose:

From TypeCompose:

newtype Flip (~>) b a = Flip { unFlip :: a ~> b }

http://hackage.haskell.org/packages/archive/TypeCompose/0.6.3/doc/html/Control-Compose.html#t:Flip

另外,如果某个东西是两个参数的函子,你可以把它变成双函子:

Also, if something is a Functor in two arguments, you can make it a bifunctor:

http://hackage.haskell.org/packages/archive/category-extras/0.44.4/doc/html/Control-Bifunctor.html

(或者,在后来的 category-extras 中,更通用的版本:http://hackage.haskell.org/packages/archive/category-extras/0.53.5/doc/html/Control-Functor.html#t:Bifunctor)

(or, in a later category-extras, a more general version: http://hackage.haskell.org/packages/archive/category-extras/0.53.5/doc/html/Control-Functor.html#t:Bifunctor)