編輯所有內容haskell。字轉換爲二進制數
我需要將字轉換爲二進制數。 與你的一點幫助,我得到這個
import Data.Char
blCo :: String -> String
blCo xs = concatMap lett2num) xs
lett2num :: Char -> Int
lett2num y
| (ord 'A' <= ord y) ord 'z') = (ord y - ord 'a') +1
num2bin :: Int -> String
num2bin n
| n >= 0 = ctive number"
where n2b 0 = []
n2b n = n `mod` 2 : n2b (n `div` 2)
GHC告訴我犯錯誤不undertsand它 錯誤:
Couldn't match expected type `Char' against inferred type `String'
In the first argument of `(:)', namely `num2bin (lett2num x)'
In the expression: num2bin (lett2num x) : blCo xs
In the definition of `blCo':
blCo (x : xs) = num2bin (lett2num x) : blCo xs
什麼是` x:xs` in blCo for?去掉它。 – kennytm 2011-01-13 17:43:29
你能告訴我們翻譯給你的錯誤嗎?當你去看醫生時,你確實告訴他什麼傷害,在哪裏,不是嗎? – 2011-01-13 17:45:10
blCo :: String - > Int blCo x = num2bin(lett2num x) 應該這樣嗎? – Tonja 2011-01-13 17:45:18