This is simple code designed to take a decimal number and return a string representing the equivalent in binary.
b2d :: Int -> String
b2d 1 = "1"
b2d x = show (x `mod` 2) ++ b2d x/2
However, when I try to run this through hugs, it gives me an error:
:3 - Instance of fractional [Char] required for definition of b2d
I don't know what this means. Can anyone tell me how to fix it?
Cheers.
you probably wanted (function calls have higher precedence than operators):
b2d (x/2)
also your first case should probably not take 2 arguments
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With