haskell. words into binary numbers
- by Katja
I need to convert words into binary numbers.
With a bit help of yours I got this
blCo::String -> Integer
blCo x = num2bin(lett2num x)
blCo (x:xs)
| x:xs = num2bin(lett2num x):blCo xs
num2lett :: Int -> Char
num2lett n
| (n <= ord 'A') && (n <= ord 'Z') = chr(ord 'A'+ n - 1)
| (n <= ord 'a') && (n <= ord 'Z') = chr(ord 'A'+ n - 1)
num2bin :: Integer -> String
num2bin n
| n >= 0 = concatMap show (reverse ( n2b n))
| otherwise = error "num2bin: negative number"
where n2b 0 = []
n2b n = n `mod` 2 : n2b (n `div` 2)
he tells me a mistake.I dont undertsand it
mistake:
Couldn't match expected type `Char' against inferred type `String'
In the first argument of `lett2num', namely `x'
In the first argument of `num2bin', namely `(lett2num x)'
In the expression: num2bin (lett2num x)