[英]What is a Cohoist in scalaz?
The scalaz defines a Cohoist
: scalaz定义了一个
Cohoist
:
trait Cohoist[F[_[_], _]] extends ComonadTrans[F] {
def cohoist[M[_], N[_]: Comonad](f: M ~> N): F[M, ?] ~> F[N, ?]
}
where ComonadTrans
is defined: 其中定义了
ComonadTrans
:
trait ComonadTrans[F[_[_], _]] {
def lower[G[_]: Cobind, A](a: F[G, A]): G[A]
}
The question is how to treat this type? 问题是如何对待这种类型? Can someone give an explanation in a few words or give an example?
有人可以用几句话给出解释或举例吗?
ComonadTrans
isn't really important to understanding cohoist
, which is similar to a higher-order version of map. ComonadTrans
对于理解cohoist
并不是很重要,它类似于高阶版的地图。
map
can be reformulated, by flipping the arguments around, as 通过翻转周围的论点,可以重新制定
map
[A, B](A => B) => (F[A] => F[B])
In other words it lifts a function into F
. 换句话说,它将一个函数提升为
F
~>
is just ~>
只是
F ~> G
[A]F[A] => G[A]
With that you can expand the signature of cohoist
有了它,你可以扩大
cohoist
的签名
[M[_], N[_]: Comonad]([A]M[A] => N[A]) => ([A]F[M, A] => F[N, A])
(the two A
s cannot be combined and pulled to the initial tparam list; I don't want to go into detail here beyond saying "that would not work") (这两个
A
不能合并并拉到最初的tparam列表;我不想在此处详细说明“那不起作用”)
So just like map, it lifts a function (M to N transformer) into F
, making an "F of M" to "F of N" transformer. 所以就像map一样,它将一个函数(M到N变换器)提升到
F
,将“F of M”改为“F of N”变换器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.