I guess it’s not.
For me, the Haskell way seems to be natural: the base case is the first element of the list, and the folding begins with the second element.
In Daml, I’m not sure about the pattern:
I guess it’s not.
For me, the Haskell way seems to be natural: the base case is the first element of the list, and the folding begins with the second element.
In Daml, I’m not sure about the pattern:
Well spotted! f x y
should be f y x
here.
Permit me to briefly soapbox that foldl1 and foldr1 have superior alternatives whose typechecking would have caught this—and, perhaps more importantly, made it impossible to disagree about which argument should be the “accumulator”.
Just to check @gyorgybalazsi you got this foldl1
from DA.Foldable
rather than DA.List
, right?
Yes, from Foldable
I’ve opened a PR to fix this.