Haskell-ghci,没有找到 toUpper 函数?

Haskell-ghci, function toUpper not found?

我现在已经安装了 ghci 版本 8.6.2 并遵循我编写的教程:

toUpper "something"

但是 ghci 编译器打印出来:

Variable not in scope: toUpper :: [Char] -> t

我是否错过了一些图书馆或其他任何东西?

toUpper :: Char -> Char 不是 Prelude 的一部分,因此未导入 "implicitly"。

您可以通过以下方式导入它:

import Data.Char(toUpper)

或者只是:

import Data.Char

导入该模块中定义的所有函数、数据类型等。

请注意,它具有签名 Char -> Char,因此它仅将 单个 字符转换为其对应的大写字母。

因此您需要执行 mapping:

Prelude Data.Char> map toUpper "something"
"SOMETHING"