[Haskell-beginners] Type Class question

Malik H mhamro at gmail.com
Tue Jun 2 15:44:48 EDT 2009


I am reading article "Fun with type functions" and I have a few
questions regarding examples presented in it. Here is the code

class Add a b where
    type SumTy a b
    add :: a -> b -> SumTy a b

instance (Add Integer a) => Add Integer [a] where
    type SumTy Integer [a] = [SumTy Integer a]
    add x y = map (add x) y

Here are my questions:
1. Is type "SumTy Integer [a]" visible outside 'Add' instance?
2. If yes, how would you create and instance of that type without
using 'add' function?
3. Will function 'add x y' create the following structure [SumTy x y1,
SumTy x y2, etc...]? If not, what is 'add x y' creates?
4. How to print the result of 'add x y'?

Also, I understand the following
"instance (Ord a) => Monad a where ...."

as type of the 'a' must be an extension of type Ord.
How shall I understand code below?
  "instance (Add Integer a) => Add Integer [a]"

Thanks a lot.


More information about the Beginners mailing list