On Sat, Jun 7, 2008 at 3:03 PM, Dan Doel <[EMAIL PROTECTED]> wrote: > On Friday 06 June 2008, Andrew Coppin wrote: >> It's really quite frustrating that it is 100% impossible to write a >> single function that will process lists, arrays, sets, maps, byte >> strings, etc. You have to write several different versions. OK, so some >> functions really don't make sense for a set because it's unordered, and >> some functions don't make sense for a map, and so forth. But for >> example, if I write some complicated algorithm that uses a list to store >> data and I change that to a set instead, I now have to wade through the >> function changing every operation from a list-op into a set-op. It's >> really very annoying! > > It's not 100% impossible, depending on what exactly you're doing. For > instance... > > Set a, ByteStrings, Seq a, Map k a and [a] are Monoids > Set, Array i, Map k, Tree, Seq and [] are Foldable functors > Array i, Map k, Tree, Seq, Tree and [] are Traversable functors > > Those can get you lots of operations (folds, maps, unions...) although there > may be gaps that could be filled (Foldable is sufficient to define null, for > instance, but it isn't in Data.Foldable).
These do help in the case you want to traverse data structures that share a set of properties (e.g. are Functors). However, it doesn't address the problem of sharing an interface among Set, IntSet, ByteSet, etc. In other words there's a need for a Set type class. Hopefully type families will help us write such an interface and keep it efficient. Cheers, Johan _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe