类型¶
lib 内部的 type 声明声明了一种 C typedef,但更强大
lib X
type MyInt = Int32
end
与 C 不同,Int32 和 MyInt 不可互换
lib X
type MyInt = Int32
fun some_fun(value : MyInt)
end
X.some_fun 1 # Error: argument 'value' of 'X#some_fun' must be X::MyInt, not Int32
因此,type 声明对于由您正在封装的 C 库创建的不透明类型很有用。一个例子是 C FILE 类型,您可以使用 fopen 获取。
请参阅 类型语法 以了解 typedef 类型中使用的符号。