haskell. words into binary numbers
Posted
by
Katja
on Stack Overflow
See other posts from Stack Overflow
or by Katja
Published on 2011-01-13T17:37:08Z
Indexed on
2011/01/13
17:53 UTC
Read the original article
Hit count: 161
haskell
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)
© Stack Overflow or respective owner