Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala中的运算符求值-一个是无止境循环,另一个有效_Scala_Loops - Fatal编程技术网

Scala中的运算符求值-一个是无止境循环,另一个有效

Scala中的运算符求值-一个是无止境循环,另一个有效,scala,loops,Scala,Loops,我最近开始了Coursera专业化,其中一项作业要求对二叉树集执行union操作。我最初将其编码为: def union(that: TweetSet): TweetSet = ((left union right) union that) incl elem 但在我的测试中,它导致了一个无休止的循环。然后,我试着: def union(that: TweetSet): TweetSet = (left union (right union that)) incl elem 这一切都如我所料

我最近开始了Coursera专业化,其中一项作业要求对二叉树集执行union操作。我最初将其编码为:

def union(that: TweetSet): TweetSet = ((left union right) union that) incl elem
但在我的测试中,它导致了一个无休止的循环。然后,我试着:

def union(that: TweetSet): TweetSet = (left union (right union that)) incl elem

这一切都如我所料!现在,我很高兴它成功了,但我无法找出这两种实现之间差异的原因。你能帮我找到它吗?

这是一个很好的例子,说明用调试器处理问题会很快发现问题。这是一个很好的例子,说明用调试器处理问题会很快发现问题。