Indexer property only accepts tuple without parens. Anybody know why?

Example here:

Signature of the property says it accepts a tuple. When I use parens or a tuple bound to a name, it doesn’t work. Is there a reason for this?

1 Like

That’s because it doesn’t take a tuple: it takes several indices. You’re not actually creating a tuple when you call pixels.[9,0]. This is similar to method arguments actually: when you do eg File.WriteAllText("foo.txt", "Hello!"), you’re passing two separate arguments to the method, not one tuple.

1 Like

That last is not technically correct, Tarmil. You can try it yourself by first creating those parameters as a tuple, and then use the tuple as argument to File.WriteAllText. You will find that it works.

It is a common misunderstanding that functions and methods accept either curried parameters or tupled parameters, but that is only a matter of convention. So called tupled parameters only means that the method or function accepts one tuple. You can have as many curried and tupled as you wish, mixed in any manner. However, this picture breaks to a large extent when optional parameters and references are involved.

1 Like

Since there are overloads, it’s a bit tricky in this case to make the compiler understand. This is how it can be done.

let args = (@"foo.txt", "Hello!")
let dummy = args |> File.WriteAllText
1 Like