E4131#
The type alias is a function type, not a type constructor.
This error occurs when you try to define a method for a type alias. Aliases of a type can be used interchangeably with the type itself, and it is not possible to define method for function types. Therefore, MoonBit disallows defining methods for type aliases of function types.
错误示例#
typealias FuncAlias = (Int) -> Unit
pub fn FuncAlias::call(self : FuncAlias) -> Unit {
// ^~~~~~~~~
// Error: The type alias FuncAlias is a function type, not a type constructor.
self(0)
}
建议#
If you want to define a method for a function type, you should define a new type that wraps the function type:
type FuncWrap (Int) -> Unit
pub fn FuncWrap::call(self : FuncWrap) -> Unit {
(self._)(0)
}