list - Alternating Sum Using FOLDR (SML) -
I use Edit: I actually asked to use an anonymous function with foldr to get an optional amount from the list I'm trying to int, but keep an operator / operator mismatch error. I think I'm expecting the output to be fold / code>
1 - 3 + 5 - 7 + 9 = 5 foldr
For example, for example
l = [1,3,5,7,9] fold (FN (x, y): => x - y) l with the same expected output, but I'm still merging the same operator / operator
foldr code> foldl ) Once Rnbhik value.
foldr type ('a *' b -> 'b') - gt; 'B - & gt; 'A list - & gt; 'B' , where 'b is the result of the result of the bottom of each stage (also the initial value, which is the initial "result"); And the 'a is the type of elements in the list. Note that the combination function can be different from 'a and ' b takes an element and previous result and gives new results.
However, you need to think about a suitable initial value. What should this be? I think 0 would do:
fold-op-0 l
Comments
Post a Comment