Scala"类型"别名混乱

Tah*_*een 1 scala

我正在开设Coursera作业和第2周.本周作业并不难,但非常令人困惑.

我写下面的代码,它工作正常

def union(s:Set[Int], t:Set[Int]):Set[Int] = s union t 
Run Code Online (Sandbox Code Playgroud)

但是如果我使用type来创建Set的别名并在上面重写为

type Set = Int => Boolean
def union(s:Set, t:Set):Set = s union t
Run Code Online (Sandbox Code Playgroud)

现在我得到错误的联盟不是Set的成员

sep*_*p2k 6

def union(s:Set[Int], t:Set[Int]):Set[Int] = s union t
Run Code Online (Sandbox Code Playgroud)

这是有效的,因为Set[T]定义了一个名为的函数union,该函数在上面的代码中调用.

type Set = Int => Boolean
def union(s:Set, t:Set):Set = s union t
Run Code Online (Sandbox Code Playgroud)

这不起作用,因为函数没有名为的方法union.