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

Open
freizl opened this Issue Apr 30, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@freizl
Member

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

@freizl

This comment has been minimized.

Member

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)

@zwvista

This comment has been minimized.

zwvista commented Aug 25, 2018

看我的博客
Haskell语言学习笔记(3)map, filter, fold
https://blog.csdn.net/zwvista/article/details/54747749

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment