0
我在將數組內部的數組轉換爲記錄類型時遇到了一些麻煩。有問題的代碼是這樣的在lambda內創建記錄
let arrayToTransaction arr =
arr
|> Array.map (fun x -> splitStr [|"\n"|])
|> Array.collect
(fun x -> {
date = DateTime.Parse(x.[1]);
payee = x.[0].Substring(0, x.[0].IndexOf(','))
category = "Test category"
memo = "Parsed with my F# parser"
outflow = Single.Parse(str.Substring(str.IndexOf('-') + 1))
inflow = 0.0f
})
我得到的錯誤是
錯誤1型「」一[]」不包含字段‘日期’
但我已經正確定義了記錄類型,我知道這是因爲:
let x = { date = DateTime.Now; payee = "test"; category = "test"; memo = "test"; outflow = 0.0f; inflow = 0.0f }
工作得很好。