0

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 Answers 2

1

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
Sign up to request clarification or add additional context in comments.

4 Comments

That doesn't work, unfortunately, it says. This expression was expected to have type string -> string [] but here has type string []. Which doesn't make a lot of sense to me because the array is a collection of strings..
the problem is your splitStr call one line earlier. You're not passing in the x string at all.
Yes I figured it out literally the same time as you posted. I thought the lambda would "pipe" the x to splitStr alas it doesn't it seems.
Note: This is why it is a good idea to give line numbers of errors
0

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)

1 Comment

Right, nothing of that sort gets done implicitly. You can make it point-free if you do this though: Array.map (splitStr [|"\n"|]).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.