0
我偶然發現Haskell教程中的某些代碼似乎並不適用於我。Haskell函數將小寫字母轉換爲大寫char
fromEnum :: Char -> Int
toEnum :: Int -> Char
offset :: Int
offset = fromEnum 'A' - fromEnum 'a'
toUpper :: Char -> Char
toUpper ch = toEnum (fromEnum ch + offset)
從中摘錄的文本書指出下面的轉換函數會將小寫字母轉換爲大寫字母。然而,當我嘗試運行該腳本,我得到了以下錯誤消息:
eval.hs:1:1:
The type signature for ‘fromEnum’ lacks an accompanying binding
(The type signature must be given where ‘fromEnum’ is declared)
eval.hs:2:1:
The type signature for ‘toEnum’ lacks an accompanying binding
(The type signature must be given where ‘toEnum’ is declared)
Failed, modules loaded: none.
我是新來的Haskell,所以有人告訴我什麼,我在這裏失蹤?教科書是錯的嗎?
啊,我明白了。我想我也可以使用'import prelude hiding(...)',儘管這可能沒有意義。 – Bolboa
@Bolboa是的,你可以。但是你需要實現這些功能 - 你的代碼只提供他們的類型簽名,而不是他們的實際代碼。 – chi