Quick notes on important points

Thigs I do not like

data A = A deriving Show
data B = B deriving Show
data C = C deriving Show
data D = D deriving Show

class If1 t where ; meth1 :: x -> t
class If2 t where ; meth2 :: x -> t
instance If1 A where ; meth2 x = A
instance If2 B where ; meth2 x = B

apply_func :: If1 a => (Either a b) -> (b -> Either a c) -> Either a c
apply_func (Right x) f = f x
apply_func (Left x) _ = Left x

f :: If2 b => b -> Either a C
f b = Right C

:t apply_func (Right B) f
  apply_func (Right B) f :: If1 a => Either a C
:t apply_func (Right B :: Either D B) f
  error:
     No instance for (If1 D) arising from a use of apply_func
:t apply_func (Left A) f
  error:
     Ambiguous type variable b0 arising from a use of f
      prevents the constraint (If2 b0) from being solved.

WTF

Exercises