2011年8月22日 星期一

F# Language Concepts–Types 型別

F#裡的型別, 其實和大多數的程式語言都相同, 如int, bool, double…等, 其他內建在語言的型別包含 Tuple、清單、陣列、序列、記錄和已區分的聯集, 所以如果想知道F#可以使用什麼型別, 可以參考.Net的使用方法, 只不過F#裡一並可以使用.Net的資源, 和一般寫C#並無太多的不同。

primitive type: int, float, string
aggregate type: (其實就是class, structure, union, record, enum): Color, System.DateTime
type abbreviation: bigint
fully qualified type: System.IO.StreamWriter
array: int[], array<int>, int array
two-dimensional array: int[,]
three-dimension array: int[,,]
tuple: For example, (1,'b',3) has type int * char * int
generic type
constructed type (a generic type that has a specific type argument supplied)
function type that has a single parameter
function type that has multiple parameters
higher order function as a parameter
delegate
flexible type
其中紅色的部分, 可以算是F#裡新加入的, 也就是學習F#的人應該注意的, 因為在F#裡function也可以被當成一種型別傳入及傳出, 所以function的type, 要注意..
原文可以參考: http://msdn.microsoft.com/zh-tw/library/dd233230.aspx
基本型別: http://msdn.microsoft.com/zh-tw/library/dd233210.aspx

下一次就會介紹型別的推導, 以及他和function的關係…

沒有留言: