[Haskell-beginners] Making a generic interpreter

Erik Helin erik.helin at gmail.com
Sat May 7 11:39:44 CEST 2011


Thank you Patrick for posting your code, it helps a lot too see a
complete example!

On Sat, May 7, 2011 at 03:11, Patrick LeBoutillier
<patrick.leboutillier at gmail.com> wrote:
> instance AbsInteger Integer where
>   a `add` b = (+) a b
>   a `eq` b = absBool $ a == b
>   absInteger a = a

In my code, I did not use "a `eq` b = absBool $ a == b". Instead, I
used "a `eq` b = a == b".
I thought, since "a == b" is of type Bool, and Bool is an instance of
AbsBool, I can just return type Bool.

Why isn't this the case? What is it about typeclasses that I'm not
understanding?

I updated my code to also use "absBool", and it works great without
muti-parameter typeclasses and functional dependencies!

Patrick and Brent, thank you so much for your help! You have both
inspired me to continue my journey with Haskell :)

Btw, Patrick, do you have any small Haskell project (or can you
recommend some other project) on github (or something similar) that I
can read to see more examples of good Haskell code?



More information about the Beginners mailing list