Reputation: 115
I have a class with no explicit type a.
> class Binaer a where
> a_zu_binaer :: a -> String
And I am building an instance of that class. The function toBin
requires as input an Integer.
> instance Binaer Integer where
> a_zu_binaer b = toBin b
Doing so I get the following error:
Inferred type is not general enough
*** Expression : a_zu_binaer
*** Expected type : a -> String
*** Inferred type : Integer -> String
Is there a way to solve this problem? I can not give an explicit type for "a"
Upvotes: 0
Views: 83
Reputation: 116139
Indentation matters.
class Binaer a where
a_zu_binaer :: a -> String
This defines a class with no methods, and a completely unrelated a_zu_binaer
function.
To make that into a method, indent it.
class Binaer a where
a_zu_binaer :: a -> String
I'd recommend you write your code in a file, instead of entering it in GHCi. In GHCi, you will need to write everything on one line, or use one of the multi-line entry modes, but that's less convenient.
Upvotes: 9