[Haskell-beginners] what's a proper way to make a Set typeclass? and
why is it not done already?
Markus Läll
markus.l2ll at gmail.com
Mon Jul 5 18:35:41 EDT 2010
I started like this:
{-# LANGUAGE
MultiParamTypeClasses,
FlexibleInstances #-}
import qualified Data.List as L
class (Eq e) => Set s e where
empty :: s e
fromList :: [e] -> s e
...
..and started to implement it on a list:
instance (Eq e) => Set [] e where
empty = []
fromList xs = L.nub xs
But I can't understand, why there has to be a (Eq a) context to the
Set instance of a list, when the class definition seems to already say
it? It won't compile without it..
Secondly, why do I need FlexibleInstances -- it gives me an eror which
I don't understand ("all instance types must be of the form T a1 ...
an" and so on, and recommends to add the flexible instances.)
Also I couldn't find other elaborate Set typeclasses -- there seems to
be only the "Set a" type. Why is that(?), because you could use other
datastructures, better and worse in various ways, than the balanced
binary tree..
Markus
More information about the Beginners
mailing list