2017-10-28 85 views
-2

我創建給出Char列表的功能範圍,給出了同樣的名單,但只能用數字:哈斯克爾:可變

algarismos :: [Char] -> [Char] 

algarismos [] = [] 
algarismos (x:xs) | (isDigit x) =x:(algarismos xs) 
        | otherwise =(algarismos xs) 

我得到錯誤信息

error: Variable not in scope: isDigit :: Char -> Bool 

爲什麼isDigitx的範圍內沒有變量?

+0

什麼是實際的錯誤信息? – melpomene

+3

請始終包含實際的錯誤信息。 - 您遇到的問題可能是['isDigit' _itself_](http://hackage.haskell.org/package/base-4.10.0.0/docs/Data-Char.html#v:isDigit)不在範圍。你真的導入了'Data.Char'嗎? – leftaroundabout

+0

錯誤: 變量不在範圍內:isDigit :: Char - > Bool | 6 | algarismos(x:xs)| (isDigit x)= x:(algarismos xs) –

回答

4

只要你給我們所有的代碼,這是實際的錯誤消息:

error: Variable not in scope: isDigit :: Char -> Bool 

這是說,isDigit沒有定義,而不是別的。


您需要導入Data.Char,其中包含isDigit。你應該在你的文件的頂部:

import Data.Char (isDigit) 

這從基礎模塊Data.Char導入功能isDigit

未來,請使用hoogle尋找您需要進口的產品。