相关疑难解决方法(0)

在Scala中创建中缀运算符

我正在尝试将我的一些Haskell代码转换为Scala,并且我在创建中缀运算符时遇到了困难.

在Haskell中我说这个中缀运算符定义为:

infix 1 <=>                          // this specifies the operator precedence
(<=>) :: Bool -> Bool -> Bool        // this is the type signature of this operator (it says, it takes two Boolean values and returns a Boolean value)
x <=> y = x == y                     // this is the definition of the operator, it is mimicking the behaviour of the logical implication 'if-and-only-if'
Run Code Online (Sandbox Code Playgroud)

所以现在如果我有两个布尔值,p和q,其中p == True和q == False,p <=> q将返回False.

我的问题是如何将其转换为Scala.我看了一下在Odersky的Scala编程书中定义的Rational类,并尝试按照这个例子.这是我得到的:

class Iff (b : Boolean){
  def <=> (that …
Run Code Online (Sandbox Code Playgroud)

haskell scala

15
推荐指数
1
解决办法
2988
查看次数

标签 统计

haskell ×1

scala ×1