跳至內容

類型

lib 內部宣告的 type 是一種 C 語言的 typedef,但更嚴格。

lib X
  type MyInt = Int32
end

與 C 語言不同,Int32MyInt 並不能互換。

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 類型中使用的符號。