【发布时间】:2019-04-15 12:07:56
【问题描述】:
我现在已经安装了 ghci 版本 8.6.2 并按照我编写的教程进行操作:
toUpper "something"
但是 ghci 编译器会打印出来:
Variable not in scope: toUpper :: [Char] -> t
我想念一些图书馆或其他什么吗?
【问题讨论】:
标签: function haskell ghci toupper
我现在已经安装了 ghci 版本 8.6.2 并按照我编写的教程进行操作:
toUpper "something"
但是 ghci 编译器会打印出来:
Variable not in scope: toUpper :: [Char] -> t
我想念一些图书馆或其他什么吗?
【问题讨论】:
标签: function haskell ghci toupper
toUpper :: Char -> Char 不是Prelude 的一部分,因此不会“隐式”导入。
您可以使用以下命令导入它:
import Data.Char(toUpper)
或者只是:
import Data.Char
导入该模块中定义的所有函数、数据类型等。
注意它有签名Char -> Char,所以它只将一个单个字符转换成大写字符。
因此您需要执行mapping:
Prelude Data.Char> map toUpper "something"
"SOMETHING"
【讨论】: