什么是投影仪 [英] What is a kind projector

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

问题描述

我一直在研究FP及其周围的所有东西,我发现实物投影仪的概念写在某个地方,没有细节也没有解释.

I've been digging into FP and everything that surrounds it, and I found the concept of kind projector written somewhere, without details nor explanations.

我唯一发现的是这个 github项目,我开始考虑是否是指这个特定项目,还是FP中的一些通用概念?

The only thing I found was this github project, and I'm starting to think if it was referring to this particular project, or to some generic concept in FP?

那么,什么是投影仪?为什么有用? (如果可能,您可以提供示例,资源等吗?)

So, what is a kind projector? Why is it useful? (if possible, can you provide examples, resources, etc?)

推荐答案

这确实只是您链接到的Scala编译器的特定插件的名称有点尴尬.我认为它对自己没有任何意义,但是有点符合其目的.

This is indeed just a slightly awkward name for the specific plugin for the Scala compiler you linked to. I don't think it has any significance to itself, but it kind of fits its purpose.

该插件的作用是为Scala通常的lambdas解决方案提供替代语法,该替代方法使用名为

What the plugin does is to provide an alternative syntax to Scala's usual workaround for type lambdas, which uses a language feature called type projections.

说您想为Either实现Functor.现在,Functor需要种类* -> *,而Either需要种类* -> * -> *.因此,我们需要首先修复第一个参数,然后才能为部分应用的类型构造函数提供实现.您可以在常规" Scala中执行此操作的唯一方法是:

Say you wanted to implement Functor for Either. Now, Functor requires kind * -> *, whereas Either has kind * -> * -> *. So we need to first fix the first argument, and can then provide the implementation for the partially applied type constructor. The only way you can do this in "regular" Scala is this:

implicit def eitherIsFunctor[A]: Functor[{type λ[X] = Either[A, X]}#λ] = { ... }

其中,{type λ[X] = Either[A, X]}是匿名结构类型,仅立即用于投影" λ,即我们真正想要的类型.在Haskell中,您只能说

where {type λ[X] = Either[A, X]} is an anonymous structural type, which is only immediately used to "project out" λ, the type we actually want. In Haskell, you could just say

instance Functor (Either a) where ...

其中部分应用了Either(并且a被自动量化).

where Either is partially applied (and a is quantified over automatically).

该插件允许人们用看起来更像Scala中常见的部分应用程序的东西替换投影,即Either[A, ?],而不是难以理解的{type λ[X] = Either[A, X]}#λ(我还提供了通用类型的lambda,我认为,总是通过将其转换为匿名类型和预测).

The plugin allows one to replace the projection with something that looks more like a usual partial application in Scala, namely Either[A, ?], instead of the hardly understandable {type λ[X] = Either[A, X]}#λ (and also provides general type lambdas, I think, always by converting them down to anonymous types and projections).

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

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