Skip to content
Discussions/App Development/In Daml, `foldl1` works differently from Haskell, is this intentional?Forum ↗

In Daml, `foldl1` works differently from Haskell, is this intentional?

App Development5 posts377 views5 likesLast activity Jan 2022
GY
gyorgybalazsiOP
Jan 2022

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:

ST
Stephen
Jan 2022

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”.

ST
Stephen
Jan 2022

Just to check @gyorgybalazsi you got this foldl1 from DA.Foldable rather than DA.List, right?

GY
gyorgybalazsi
Jan 2022

Yes, from Foldable

ST
Stephen
Jan 2022

I’ve opened a PR to fix this.

← Back to Discussions