The reason I like this is that it lets you turn fold into sum easily, something like,
let fold collection initial f =
let mutable res = initial
for item in collection do
res <- f res item
res
let sum (numbers: #INumber<'t>) = fold numbers (INumber<'t>.Zero) (+)
let product (numbers: #INumber<'t>) = fold numbers (INumber<'t>.One) (*)
or however that syntax is going to work out. Then there are a lot of other things you can do with that sort of pattern. Being able to write more complex stuff, like weighted average and standard deviation, is pretty hot.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
You are absolutely right, thanks for pointing that!
Indeed my example might not have been the most explicit one, I should have talked about summing only taxes (double) to avoid confusion
The reason I like this is that it lets you turn
fold
intosum
easily, something like,or however that syntax is going to work out. Then there are a lot of other things you can do with that sort of pattern. Being able to write more complex stuff, like weighted average and standard deviation, is pretty hot.