如何在 haskell 中旋转文本,以便仅旋转单个单词而不旋转整个文本?
该文本需要在输入自然数时向左旋转,在输入负数时向右旋转。所以:
rotate 1 "foo bar baz" = "ofo rba zba"
rotate (-1) "foo bar baz" = "oof arb azb"
还要补充一点,我可以将文本分解为行,然后是单词,我知道所有的行,非行,单词,非单词。我无法理解向左或向右移动文本的定义,我需要使用 head 函数吗?
This text needs to rotate left with a natural number and rotate right when a negative number is entered. So:
rotate 1 "foo bar baz" = "ofo rba zba"
rotate (-1) "foo bar baz" = "oof arb azb"
Also to add i can break down the text into lines and then words, i know all the lines, unlines, words, unwords. I'm having trouble with the definitions for moving the text left or right, do i need to use the head function?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了构建您想要的功能,我为您提供了一些砖块。不包括汇编指令:
(通过 hoogle)
To build the function you want, I provide you some bricks. Assembly instructions not included:
(Documentation links found through hoogle)