3
例如,如果我儘量延長int
,與int
不是類型的真實姓名,這個代碼將失敗:爲什麼F#不支持與它的類型縮寫擴展系統類型?
type int with
member this.IsEven = this % 2 = 0
我必須使用System.Int32
代替:
type System.Int32 with
member this.IsEven = this % 2 = 0
//test
let i = 20
if i.IsEven then printfn "'%i' is even" i
爲什麼能「T我用的類型縮寫int
?
因爲你不能。因爲他們沒有這樣寫。因爲。 – Will