Closed hw202207 closed 1 year ago
<td>Use foldr</td> <td> LHS: <code> foldr f z (concat x) </code> <br> RHS: <code> foldr (foldr f) z x </code>
foldr
(a -> b -> b) -> b -> [a] -> b
concat :: [[a]] -> [a]
foldr f z (concat x)
x :: [[a]]
z :: b
f :: a -> b -> b
foldr (foldr f) z x
foldr f
[a] -> b -> b
foldr f :: b -> [a] -> b
foldr (flip $ foldr f) z x
v3.5
You're right and I think the same applies to:
foldr f z (concatMap g x)
foldr (foldr f . g) z x
I removed both rules: #1520
I meant this suggestion
Here is my reasoning
foldr
has type(a -> b -> b) -> b -> [a] -> b
for the sake of simpler reasoning.concat :: [[a]] -> [a]
foldr f z (concat x)
, if it compile, we gotx :: [[a]]
z :: b
f :: a -> b -> b
foldr (foldr f) z x
is correct,foldr f
has to have type[a] -> b -> b
givenx :: [[a]]
from previous step.foldr f :: b -> [a] -> b
givenf :: a -> b -> b
from previous step.foldr (flip $ foldr f) z x
Which version report this hint?
v3.5