haskell – 为什么Data.Text示例不适合我?

haskell – 为什么Data.Text示例不适合我?,第1张

概述这是我在ghci中尝试做的事情: import Data.Textstrip " abc " 我收到此错误消息: <interactive>:1:6: Couldn't match expected type `Text' against inferred type `[Char]' In the first argument of `strip', namely `" a 这是我在ghci中尝试做的事情:
import Data.Textstrip "  abc  "

我收到此错误消息:

<interactive>:1:6:    Couldn't match expected type `Text' against inferred type `[Char]'    In the first argument of `strip',namely `"  abc  "'    In the Expression: strip "  abc  "    In the deFinition of `it': it = strip "  abc  "

我期待这个工作,因为它是在许多网页上给出的,包括这个答案:In Haskell,how do you trim whitespace from the beginning and end of a string?

我究竟做错了什么?

解决方法 您需要启用 overloaded string literals才能将字符串文字用作文本值(否则字符串文字将始终具有String = [Char]类型).

如果没有重载的字符串文字,则必须使用pack从String创建Text,因此:

strip $pack "  abc  "
总结

以上是内存溢出为你收集整理的haskell – 为什么Data.Text示例不适合我?全部内容,希望文章能够帮你解决haskell – 为什么Data.Text示例不适合我?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1128409.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存