[Haskell-beginners] Dependent and independent variables in foldl and foldr
Lawrence Bottorff
borgauf at gmail.com
Sat Jan 16 22:10:47 UTC 2021
I have this
myLength1 = foldl (\n _ -> n + 1) 0
and this
myLength2 = foldr (\_ n -> n + 1) 0
I am guessing that foldl knows to assign the accumulator-seed argument to
the dependent variable and the list argument's elements recursively to the
independent variable; and with foldr to do the opposite. Is this a fair
assumption? BTW, where can I get a look at the code for fold functions; or
does the type definition answer my original question? Not really able to
decipher it so well
:t foldl
foldl :: Foldable t => (b -> a -> b) -> b -> t a -> b
LB
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20210116/64eb4f96/attachment.html>
More information about the Beginners
mailing list