[Haskell-cafe] Bytestrings and [Char]
Stephen Tetley
stephen.tetley at gmail.com
Wed Mar 24 08:48:07 EDT 2010
Hi Alberto
I rather doubt a valuable set of type classes that is suitable for all
containers exists, I'm afraid.
If you consider containers as the containers package, the data
structures are all (?) functorial - but they have different shapes,
so e.g. a cons operation makes sense on the linear ones
(Data.Sequence, Data.List) but not on Data.Map, Data.Tree. 'cons' is
analogous to 'insert' but 'insert' exactly describes the operation on
maps whereas 'cons' doesn't, similarly 'insert' doesn't describe the
'cons' operation on lists exactly as it doesn't indicate the position
of where it adds to the list.
Now, if you partition the type classes into small groups you get over
the fact that some operations make sense on certain 'shapes' of data
structure, but there are still subtle type differences that aren't
conducive to type classes - e.g. ByteString and Data.Text aren't
functorial so map is type restricted:
map :: (Word8 -> Word8) -> ByteString -> ByteString
Also, while ListLike does provide default definitions for many ops I'm
guessing its more important for performance to redefine them, so the
defaults definitions aren't adding much.
There might be a couple of useful new type classes waiting in the
wings, e.g a destroy one as per view in Data.Sequence, but I doubt
that a proliferation of classes will generally make programs clearer
or more efficient and it would introduce more instances of problems
that we already have with Num type class.
class Destroy f where
destroy :: f a -> (a, Maybe (f a))
Best wishes
Stephen
More information about the Haskell-Cafe
mailing list