Haskell:使用部分应用程序将列表 xs 与列表 yss 中的每个列表一起压缩
嘿,我正在复习周五即将举行的函数式编程考试,我正在做我们讲师给出的练习。我遇到了一个需要帮助的问题:
6。 a) 编写一个函数,将给定列表 xs 与列表列表 yss 中的每个列表进行压缩。使用部分 在定义函数时尽可能使用应用程序和 lambda 表达式。 b) 编写一个函数,用给定的列表 xs 压缩列表 yss 中的每个列表。使用部分 在定义函数时尽可能使用应用程序和 lambda 表达式。 该问题的 a) 部分和 b) 部分的解决方案之间的差异部分说明了 应用函数必须以正确的顺序获取参数。
目前我对 (a) 的了解是:
zipAll = (\xs (ys:yss) -> [(zip xs ys)] ++ zipAll xs yss)
我知道这并不详尽,但有人能给我一些指示吗?
Hey I'm just revising for my functional programming exam coming up on friday and I'm just working through exercises given by our lecturer. I've come across one which I neep a bit of help on:
6. a) Write a function that zips a given list xs with every list in a list yss of lists. Use partial
applications and lambda expressions to the greatest extent possible in defining your function.
b) Write a function that zips every list in a list yss of lists with a given list xs. Use partial
applications and lambda expressions to the greatest extent possible in defining your function.
The difference between your solutions to part a) and part b) of this problem illustrates that partially
applied functions must take their arguments in the correct order.
What I have at the moment for (a) is :
zipAll = (\xs (ys:yss) -> [(zip xs ys)] ++ zipAll xs yss)
It's non-exaustive I know but could anyone give me some pointers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看来您只是缺少使该功能正常工作的基本情况。基本情况是
我可能会将参数移到方程的右侧:
但这只是风格问题。
(b) 部分的解决方案是相同的,只是参数的顺序相反,例如
It seems like you are just missing your base case to make the function work. The base case would be
I would probably move the parameters to the right side of the equation instead:
but that is just at matter of style.
The solution for part (b) is the same, except that the order of the parameters is reversed, like
没关系,我解决了:
只是希望我现在没有发布这个:P
Its fine, I worked it out:
Just wish I hadn't posted this now :P