0
votes

I'm getting this error when I try to compile

The operator 'expr.[idx]' has been used on an object of indeterminate type based on information prior to this program point. Consider adding further type constraints

This is the code

let convertFile fileName =
    let arrayToTransaction (arr: string[]) =
        arr 
        |> Array.map (fun x -> splitStr [|"\n"|])
        |> Array.map 
            (fun x -> { 
                        date = DateTime.Parse(x.[1]);
                        payee = x.[0].Substring(0, x.[0].IndexOf(','))
                        category = "Everyday Expenses: Groceries/Food"
                        memo = "Parsed with my F# parser"
                        outflow = Single.Parse(x.[2].Substring(str.IndexOf('-') + 1))
                        inflow = 0.0f
                      })
2

2 Answers

1
votes

The solution is to do exactly what the error message says, and add a type annotation:

|> Array.map 
            (fun (x:string[]) -> { 
                        date = DateTime.Parse(x.[1]);
                        payee = x.[0].Substring(0, x.[0].Index
0
votes

I figured it out, the problem was this line

    |> Array.map (fun x -> splitStr [|"\n"|])

Because splitStr is a helper function that takes two arguments, however I thought that the lambda would "pipe" the x into it but it doesn't work that way I noticed so changing it to this worked.

    |> Array.map (fun x -> splitStr [|"\n"|] x)