简体   繁体   English

为什么Scalaz中的A => M [A]没有> =>半群?

[英]Why is there no >=> semigroup for A => M[A] in Scalaz?

This is a followup to my previous question 这是我上一个问题的后续内容

Kleisli defines two operators <=< (compose) and >=> (andThen). Kleisli定义了两个运算符<=< (compose)和>=> (andThen)。 The >=> looks very natural for me and I don't understand how <=< can be useful. >=>对我来说看起来很自然,我不明白<=<如何有用。

Moreover, it looks like there is no >=> semigroup for A => M[A] but the <=< semigroup does exist. 此外,看起来A => M[A]没有>=>半群,但<=<半群确实存在。

What is the rationale behind it ? 它背后的理由是什么?

compose (or <=< ) is a little more natural when translating between point-free and non point-free styles. 在无点和无点样式之间进行翻译时, compose (或<=< )更自然一些。 For example, if we have these functions: 例如,如果我们有这些功能:

val f: Int => Int = _ + 1
val g: Int => Int = _ * 10

We get the following equivalences: 我们得到以下等价物:

scala> (f andThen g)(3) == g(f(3))
res0: Boolean = true

scala> (f compose g)(3) == f(g(3))
res1: Boolean = true

In the compose case the f and g are in the same order on both sides of the equation. compose情况下, fg在等式的两边具有相同的顺序。

Unfortunately Scala's type inference often makes andThen (or >=> ) more convenient, and it tends to be more widely used than compose . 不幸的是,Scala的类型推断经常使得andThen (或>=> )更方便,并且它往往比compose更广泛地使用。 So this is a case where mathematical conventions and the quirks of Scala's type inference system are at odds. 因此,这是一个数学约定和Scala类型推理系统的怪癖不一致的情况。 Scalaz (not too surprisingly, given the culture of the project) chooses the math side. Scalaz(考虑到项目的文化,并不太令人惊讶)选择了数学方面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM