
Antoine Latter wrote:
Sure! Using type-families:
class Container c where type Elem c insert :: Elem c -> c -> c
instance Container [a] where type Elem [a] = a insert = (:)
instance Container ByteString where type Elem ByteString = Word8 insert = BS.cons
instance Ord a => Container (Set a) where type Elem (Set a) = a insert = Set.insert
That's more or less how I was hoping it works. (Was unsure of the actual syntax, and the documentation is rather terse.) So there's a class called Container that has a _type_ that is _associated_ with it, representing the type of the elements? And you can set that type to be either a type variable or an explicit type?
Now the hard part is coming up with a proper API and class hierarchy.
So... exactly like in every OOP language in existence then? ;-)