Usually, the PureScript compiler yells about this code:
instance foldableSomething :: Foldable ... where
foldMap = ...
foldl = foldlDefault
foldr = foldrDefault
Instead asking you to eta-expand it to:
instance foldableSomething :: Foldable ... where
foldMap = ...
foldl t = foldlDefault t
foldr t = foldrDefault t
However, the following type:
newtype Scope b f a = Scope (f (Var b (f a)))
Makes the earlier code compile without warning, but generates code that looks like:
var foldableScope = function (dictFoldable) {
return new Data_Foldable.Foldable(function (dictMonoid) {
// ...
},
Data_Foldable.foldlDefault(foldableScope(dictFoldable)),
Data_Foldable.foldrDefault(foldableScope(dictFoldable)));
};
which results in a stack overflow as soon as any of the three methods is called.
Eta-expanding the code solves this, and generates the proper code, where the last two methods instead look like:
}, function (t) {
return Data_Foldable.foldlDefault(foldableScope(dictFoldable))(t);
}, function (t) {
return Data_Foldable.foldrDefault(foldableScope(dictFoldable))(t);
});
The fact that the compiler does not complain in this case could potentially be a bug.
Usually, the PureScript compiler yells about this code:
Instead asking you to eta-expand it to:
However, the following type:
Makes the earlier code compile without warning, but generates code that looks like:
which results in a stack overflow as soon as any of the three methods is called.
Eta-expanding the code solves this, and generates the proper code, where the last two methods instead look like:
The fact that the compiler does not complain in this case could potentially be a bug.