type class VS struct/functor

¾È±â¿µ kyagrd@bawi.org
Sat, 19 Jan 2002 10:14:22 +0900


I prefer Haskell style type classes because
using them one can overload functions.
e.g.

\begin{code}
class Container a where
  celem :: Eq b => b -> a b -> Bool
  cmap :: (Eq b, Eq c) => (b->c) -> a b -> a c

data MyList a = MyList [a] deriving Show

instance Container MyList where
  celem x (MyList l) = elem x l
  cmap f (MyList l) = MyList (map f l)
\end{code}

What does ML struct/functor have anything
better than type classes ? For the user type
classes feels like implicit functor istantiations
to specific sturucture, and struct/functor seems
just bugglling the user to do more typing which
can be automated by using type classes.

Type classes are more than automatic functor
instantiation since it can construct hierarcy
between types and you can implement implicit
type conversoins.

I think ML, especially nML - the Korean dialact of ML
being developed in ROPAS(http://ropas.kaist.ac.kr/) -
should throw away struct/functor or deprecate them
and move to type classes.

p.s. Am I asking ML to metamorph into eager Haskell ? :-)