Closed amarqueslee-da closed 2 years ago
@amarqueslee-da How have you found out about this? This is quite a remarkable bug that has been lurking in the standard library since it was first implemented around 4 years ago. It's quite impressive it was never detected and we're wondering how much the Foldable
type class is useful for end users.
Affected Daml version
1.18.0
Bug description
If I implement a new datatype and give an instance of
Foldable
withfoldMap
andfoldr
implementations, the defaultfoldl
implementation will fold over my data structure from right-to-left instead of left-to-rightTo reproduce
I invented a superficial type that just wraps the standard list:
And wrote a test scenario for foldl that I expect to pass:
The test passes when the
foldl
implementation is provided, but fails if thefoldl
implementation is commented out with this error:Expected behavior
I would expect the provided test scenario to pass, even when the provided implementation of
foldl
is commented-out.Additional context
The haskell stdlib default implementation for
foldl
appears to use theDual
wrapper monoid to reverse composition of functions passed toEndo
:The daml implementation looks like it just uses
Endo
directly, passingflip f
.