Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

哪位大牛解释一下Real World Haskell第95页的myFoldl函数是怎么回事呗。。。想了好久,写写画画了好久,理解不了啊。 by btnz #132

freizl opened this issue Apr 30, 2018 · 2 comments


Copy link

@freizl freizl commented Apr 30, 2018

Real World Haskell第95页
In fact, we can even write foldl using foldr!
--file: ch04/Fold.hs
myFoldl :: (a -> b -> a) -> a -> [b] -> a
myFoldl f z xs = foldr step id xs z
where step x g a = g (f a x)

@freizl freizl added the migration label Apr 30, 2018
Copy link
Member Author

@freizl freizl commented Apr 30, 2018

myFoldl :: (a->b->a)->a->[b]->a
myFoldl f z xs = foldr step id xs z
where step x g a = g (f a x)
f :: a->b->a
z :: a
xs :: [a]
x :: a
g :: a->b
step :: a->(b->c)->b->c

foldr :: (a->b->b)->b->[a]->b
foldr :: (a->(b->c)->(b->c))->(b->c)->[a]->(b->c)

Copy link

@zwvista zwvista commented Aug 25, 2018

Haskell语言学习笔记(3)map, filter, fold

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.