Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Instance of fractional [Char] required for definition?

Tags:

string

haskell

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.

like image 871
Alistair Avatar asked Dec 08 '22 06:12

Alistair


1 Answers

you probably wanted (function calls have higher precedence than operators):

b2d (x/2)

also your first case should probably not take 2 arguments

like image 139
newacct Avatar answered Jan 19 '23 01:01

newacct