简体   繁体   English

在scalaz中使用Monoid运算符:| + | 不是Some [Double]的成员

[英]Using Monoid operators in scalaz: |+| not a member of Some[Double]

What's missing to get this working? 要使它正常工作,缺少什么?

import scalaz._
import Scalaz._

val r = Some(1.0) |+| None
val r1 = None[Double] |+| Some(1.0)

I am getting the following: 我得到以下信息:

Error:(4, 25) value |+| 错误:(4,25)值| + | is not a member of Some[Double] lazy val r = Some(1.0) |+| 不是Some [Double] lazy val r = Some(1.0)| + |的成员 None 没有

                   ^

The problem is that a Monoid over Double is not lawful as the associativity rule can be invalidated in some cases by floating point arithmetic approximation. 问题是,一个MonoidDouble是不合法的关联性规则可以在某些情况下浮点运算近似无效。 For this reason scalaz left that instance out of the main project and included it instead in the scalaz-outlaws one. 因此,scalaz将该实例从主项目中移出,而是将其包含在scalaz-laws中

Include that library if you need to have an instance for Double but remember that there is a reason for this and consider your use case (eg if you are processing money transactions using floating point arithmetic you are probably doing something wrong). 如果需要为Double拥有一个实例,请包括该库,但请记住有一个原因,并考虑您的用例(例如,如果您使用浮点算法处理货币交易,则可能做错了事)。

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

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