这是我在ghci中尝试做的事情:
import Data.Text strip " 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 "