💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
函数返回类型的合一可能涉及Void类型(第2.1.5),需要一个清楚的定义什么和Void统一。Void描述一个缺乏的类型,它不能分配为任何其他类型,即使是Dynamic 。这就是说如果一个函数显式声明返回 Dynamic,它不能返回 Void。 > Unification of function return types may involve the Void-type (2.1.5) and requires a clear definition of what unifies with Void. With Void describing the absence of a type,it is not assignable to any other type, not even Dynamic. This means that if a function is explicitly declared as returning Dynamic, it cannot return Void. 相反同样适用:如果一个函数声明一个Void类型返回,它不能返回Dynamic或者其他任何类型。然而,合一的方向在分配函数的类型时是允许的。 > The opposite applies as well: If a function declares a return type of Void, it cannot return Dynamic or any other type. However, this direction of unification is allowed when assigning function types: ~~~ var func:Void->Void = function() return "foo"; ~~~ 右手函数显然是Void->String 类型,但我们可以分配它到Void->Void类型的变量 func 。这是因为编译器可以安全的假定返回类型是不相干的,因为它不能被分配到任何 非Void 类型。 > The right-hand function clearly is of type Void->String,yet we can assign it to the variable func of type Void->Void. This is because the compiler can safely assume that the return type is irrelevant, given that it could not be assigned to any non-Void type.