Reputation: 15
The following code to enumerate "backwards binary"
bin :: [Char] -> Int
bin a = temp (a, 1)
where
temp :: ([Char], Int) -> Int
temp ([], n) = 0
temp (('1':x), n) = temp(x, (n*2)) + 1*n
temp (('0':x), n) = temp(x, (n*2))
produces the following error:
TYPE - Unresolved Overloading
*** Type : Num [Char] => Int
*** Expression : Bin 1001
Similar code worked fine when it was [Int] -> Int, I have no idea why it doesn't work this way.
Upvotes: 0
Views: 295
Reputation: 24334
You are using the function with incorrect type, that is Int
(1001
) when it really epects [Char]
, e.g. bin ['1','0','0','1']
.
Upvotes: 1