如何实现无点交互?
shortLinesOnly :: IO ()
shortLinesOnly = interact result
where
shortLength = 11
onlyShorts = (<= shortLength) . length
shortLines = filter onlyShorts . lines
result = unlines . shortLines
interact result = getContents >>= putStr . result
在上面的代码中,我如何以点自由风格编写interact函数。
shortLinesOnly :: IO ()
shortLinesOnly = interact result
where
shortLength = 11
onlyShorts = (<= shortLength) . length
shortLines = filter onlyShorts . lines
result = unlines . shortLines
interact result = getContents >>= putStr . result
In the above code how can I write the interact function in point free style.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
步步:
Step by step:
最好的答案是:不要。对于这个特定的示例,唯一会发生的变化是您的代码的可读性会降低。你原来的尖头变体非常好。
在某些情况下,最好避免 pointfree 风格。这是其中之一,因为你的论点不经历线性数据流。它更适合用来为其他东西构建数据流。例子:
The best answer is: Don't. For this particular example the only change that would make is that your code would be less readable. Your original pointy variant is perfectly fine.
In certain cases it is better to avoid pointfree style. This is one of them, because your argument does not undergo linear data flow. It is rather used to build the data flow for something else. Example: