I currently use this function
let inc (i : int ref) =
let res = !i
i := res + 1
res
to write things like
let str = input.[inc index]
How define increment operator ++, so that I could write
let str = input.[index++]
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You cannot define postfix operators in F# – see 4.4 Operators and Precedence. If you agree to making it prefix instead, then you can define, for example,
and use it as below:
UPDATE: as fpessoa pointed out
++cannot be used as a genuine prefix operator, indeed (see here and there for the rules upon characters and character sequences comprising valid F# prefix operators).Interestingly, the unary
+can be overloaded for the purpose:allowing
Nevertheless, it makes sense to mention that the idea of iterating an array like below
for the sake of “readability” looks at least strange in comparison with the idiomatic functional manner
which some initiated already had expressed in comments to the original question.