我是一个Haskell新手,试图完成一个Caesar密码练习.
在一个.hs
文件中,我定义了以下函数:
let2int :: Char -> Int
let2int c = ord c - ord 'a'
Run Code Online (Sandbox Code Playgroud)
然后我尝试通过键入将其加载到GHCi中:l caeser.hs
,我收到以下错误消息:
[1 of 1] Compiling Main ( caeser.hs, interpreted )
caeser.hs:2:12: Not in scope: `ord'
caeser.hs:2:20: Not in scope: `ord'
Run Code Online (Sandbox Code Playgroud)
从我正在使用的书中,我的印象是ord
并且chr
是用于在字符和整数之间进行转换的标准函数,但似乎很明显我需要"导入"它们或其他东西.这是怎么做到的?
Pau*_*son 20
它们是标准功能,但您需要先从正确的模块导入它们.加
import Data.Char
Run Code Online (Sandbox Code Playgroud)
到ceaser.hs它应该工作.
有关编译器附带的完整库集,另请参见http://www.haskell.org/ghc/docs/latest/html/libraries/index.html.
在"Haskell 2010"中,ord
生活在Data.Char
所以你会想要import Data.Char
或import Data.Char (ord)
在"Haskell 98"中,ord
可以在模块中找到Char
.
查找功能及其模块的绝佳工具是
http://www.haskell.org/hoogle/
归档时间: |
|
查看次数: |
12607 次 |
最近记录: |