0

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"

1 Answer 1

9

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.