ZVON > References > Haskell reference
| Indexes | >> Syntax << | Prelude | Ratio | Complex | Numeric | Ix | Array | List | Maybe | Char | Monad | IO | Directory | System | Time | Locale | CPUTime | Random

Name classes
Description
Related:
Bibliography: Type Classes and Overloading [ A Gentle Introduction to Haskell ]
Standard Haskell Classes [ A Gentle Introduction to Haskell ]

Example 1
Program source: 

class AAA a where
  (+++) :: a -> a -> a	    
  (///) :: a -> a -> a
  (***) :: Num a => a -> a -> a

  x *** y = x * x * y

instance AAA Double where
  x +++ y = 2*x + y
  x /// y = x/2 + y

instance AAA Integer where
  x +++ y = 10*x + y
  x /// y = x `div` y

Input: (2::Integer) +++ (4::Integer)

Output: 24

Input: (2::Double) +++ (4::Double)

Output: 8.0

Input: (2::Integer) *** (4::Integer)

Output: 16

Input: (2::Double) *** (4::Double)

Output: 16.0