这是我在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?
我做错了什么?
答案 0 :(得分:16)
您需要启用overloaded string literals才能将字符串文字用作Text
值(否则字符串文字将始终具有String = [Char]
类型。)
如果没有重载的字符串文字,您必须使用pack
从Text
创建String
,所以:
strip $ pack " abc "
答案 1 :(得分:11)
您应该使用ghci -XOverloadedStrings
启动ghci,或者如果您已经在ghci中并且不想退出,请使用:set -XOverloadedStrings
动态设置标志。
答案 2 :(得分:0)
set.seed(1)
test <- rnorm(100)
dim(test) <- c(2,5,10)
apply(X = test, MAR = c(1, 2), FUN = which.min)