atupal home blog about cv

Haskell's type and typeclass

Typeclass defines behavior on types and then that can behave in that way are made instances of that typeclass. Just like interfaces in other languages:). The interfaces are achieved by defining function or just type declaration. So when we say that a type is an instance of a typeclass, we mean that we can use the function that the typeclass defines with that type.

Let's we see the definition of Eq:

class Eq a where
  (==) :: a -> a -> Bool
  (/=) :: a -> a -> Bool

Posted in Programming with :

comments powered by Disqus
Fork me on GitHub