What I want to doI want to implement an example of banana-split law.
ScriptI didn’t know how to ouptut tuple with foldr, I quited to implement it.
After following implementation, collecting foldr for only one makes the script be an example of banana-split law.
-- Before sum' = foldr (\x xs -&amp;gt; x + xs) 0 length' = foldr (\x n -&amp;gt; 1 + n) 0 average ls = sum' ls / length' ls -- After average' ls = s / l where (s, l) = ((foldr (\x xs -&amp;gt; x + xs) 0) ls, (foldr (\x n -&amp;gt; 1 + n) 0) ls)
ResultAfter all, I’ll run the script.
$ghci Prelude&amp;gt; :load banana-strip.hs Main&amp;gt; average' [1,2,3,4,5] 3.0