我是哈斯克爾的新手,試圖完成凱撒密碼演習。如何使用Haskell庫函數?
在.hs
文件中,我定義了以下功能:
let2int :: Char -> Int
let2int c = ord c - ord 'a'
然後我試圖通過鍵入:l caeser.hs
加載到這個GHCI,我得到了以下錯誤消息:
[1 of 1] Compiling Main (caeser.hs, interpreted)
caeser.hs:2:12: Not in scope: `ord'
caeser.hs:2:20: Not in scope: `ord'
從我使用的書,我的印象是,ord
和chr
是在字符和整數之間轉換的標準函數,但似乎很明顯我需要「導入」它們或其他東西。這是如何完成的?
順便說一句,你拼錯「凱撒」 – wnoise 2010-11-22 19:48:32
我一直在尋找加載從GHCI命令行庫,我發現你可以使用這個命令在命令行: `:m Data.Char` – metatron 2018-02-03 11:21:46