
Greetings, Is there a typeclass for mappings with a Data.Map-like interface, with stuff like: empty, insert, insertWithKey, unionWith etc. ? And, probably, a similar typeclass for mutable mappings like Data.Hashtable. Looks like such a thing would be useful; as for now, I see at least two applications: Data.Map and Data.Trie (bytestring-trie) - it's a pity that they have rather similar interfaces, but the latter lacks many methods and some are named in a different way. Also, Data.Map has some inconsistensies, too: for instance, it has an insertWith' but lacks a unionWith'. "One typeclass for all" would eliminate these inconsistencies. I'm asking mainly because I've been wondering why noone has yet written a mutable hashtable package with a MArray-like interface, I wrote a small thing myself and I am unsure as to what interface it should have. -- Eugene Kirpichov

On Thu, Feb 19, 2009 at 9:51 PM, Eugene Kirpichov
Greetings,
Is there a typeclass for mappings with a Data.Map-like interface, with stuff like: empty, insert, insertWithKey, unionWith etc. ? And, probably, a similar typeclass for mutable mappings like Data.Hashtable.
Looks like such a thing would be useful; as for now, I see at least two applications: Data.Map and Data.Trie (bytestring-trie) - it's a pity that they have rather similar interfaces, but the latter lacks many methods and some are named in a different way. Also, Data.Map has some inconsistensies, too: for instance, it has an insertWith' but lacks a unionWith'. "One typeclass for all" would eliminate these inconsistencies.
I'm asking mainly because I've been wondering why noone has yet written a mutable hashtable package with a MArray-like interface, I wrote a small thing myself and I am unsure as to what interface it should have.
Probably not adding anything terribly useful to this except to say that it'd be useful to me too - I've written a binding to a perfect hashing library (PerfectHash on hackage) which implements only 'fromList' and 'lookup', so a slightly more fine-grained type class hierarchy would be nice. (This particular implementation is useful when you have a lot of keys, but all known at run-time.) Mark -- A UNIX signature isn't a return address, it's the ASCII equivalent of a black velvet clown painting. It's a rectangle of carets surrounding a quote from a literary giant of weeniedom like Heinlein or Dr. Who. -- Chris Maeda

On Thu, Feb 19, 2009 at 2:46 PM, Mark Wotton
On Thu, Feb 19, 2009 at 9:51 PM, Eugene Kirpichov
wrote: Greetings,
Is there a typeclass for mappings with a Data.Map-like interface, with stuff like: empty, insert, insertWithKey, unionWith etc. ? And, probably, a similar typeclass for mutable mappings like Data.Hashtable.
There are some apparently useful classes for this sort of thing in the EdisonAPI package, with corresponding implementations in EdisonCore. Have a look.

2009/2/19 Eugene Kirpichov
Is there a typeclass for mappings with a Data.Map-like interface, with stuff like: empty, insert, insertWithKey, unionWith etc. ?
Maybe this is of interest: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/gmap Peter

Maybe this is of interest: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/gmap
The edison api is much more stable. The gmap api was already in place when I started working on it but I would prefer to at some point make it a superset of the edison api. No sense in having more than one map interface lying around. Jamie

On Thu, Feb 19, 2009 at 10:18 AM, Jamie Brandon
Maybe this is of interest: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/gmap
The edison api is much more stable. The gmap api was already in place when I started working on it but I would prefer to at some point make it a superset of the edison api. No sense in having more than one map interface lying around.
Jamie
What would really be nice is a general interface to a lot of different types of containers that was both standardized by the community AND used as the basis for lots of different libraries. For instance, the new split package is a well-crafted library for dealing with splitting lists, but it only works on lists. The exact same logic that's already there could be used for splitting ByteStrings, Lazy ByteStrings, Data.Sequences, some of the sequence types in Edison, fixed-length vectors, etc., but currently, the way the package is made forces you to use only Haskell's lazy lists. Now if we look at the zlib package, this package decompresses data into the lazy ByteString format. So you can't directly split data that comes out of zlib - you have to convert it to String and then back again, which is annoying and also imposes a performance cost. If we could figure out a way to have a general interface to "sequence-like" or "map-like" or "set-like" objects, we could make our libraries a lot more general and also more useful in combination with each other. Alex

On Thu, Feb 19, 2009 at 01:51:44PM +0300, Eugene Kirpichov wrote:
Is there a typeclass for mappings with a Data.Map-like interface, with stuff like: empty, insert, insertWithKey, unionWith etc. ? And, probably, a similar typeclass for mutable mappings like Data.Hashtable.
Here is one I wrote a while ago, feel free to use it any way you want, I bequeath the fille to the public domain. http://repetae.net/repos/jhc/Util/SetLike.hs John -- John Meacham - ⑆repetae.net⑆john⑈

Eugene Kirpichov wrote:
Looks like such a thing would be useful; as for now, I see at least two applications: Data.Map and Data.Trie (bytestring-trie) - it's a pity that they have rather similar interfaces, but the latter lacks many methods and some are named in a different way.
Are there any particular functions you're missing? Most of the not-as-generic variants that Data.Map has are in Data.Trie.Convenience, so as to keep Data.Trie lean. There are a few notable exceptions which are on the todo list (the dual-use insert&lookup and update&lookup in particular). In general I tried to keep all of the specific variants and any particularly helpful not-as-generic variants. Some of the not-as-generic variants didn't seem worth the time to wrapper given that we already have more generic variants (which Data.Map lacks) in Data.Trie and Data.Trie.Internal.
Also, Data.Map has some inconsistensies, too: for instance, it has an insertWith' but lacks a unionWith'. "One typeclass for all" would eliminate these inconsistencies.
Some of the name changes were to overcome these inconsistencies (e.g. `findWithDefault` -> `lookupWithDefault`, since we have `lookup` and not `find`). As for the original question, the gmap stuff and the Edison libraries provide some classes for this sort of thing. Last I checked the community hadn't really settled on what all should be included in such an interface (e.g. do you only have insert, delete, etc; or do you also require the very generic *By functions like Data.Trie? The former may not be helpful enough, and the latter may be too much of a burden on the instances.) If (a) the community can agree on a typeclass for maps, which (b) allows instances to have a fixed type for keys (like Data.Trie and Data.IntMap have), (c) doesn't require ghc-only extensions like associated types, and (d) doesn't have onerous package dependencies, then I'd be more than happy to offer an instance. The #c requirement is basically a subset of #a I'd assume. -- Live well, ~wren

wren ng thornton
(b) allows instances to have a fixed type for keys (like Data.Trie and Data.IntMap have),
Can't we do some type magic to automagically select Data.Trie if the key is a (strict) bytestring? -- (c) this sig last receiving data processing entity. Inspect headers for copyright history. All rights reserved. Copying, hiring, renting, performance and/or quoting of this signature prohibited.

On Fri, Feb 20, 2009 at 6:40 AM, Achim Schneider
wren ng thornton
wrote: (b) allows instances to have a fixed type for keys (like Data.Trie and Data.IntMap have),
Can't we do some type magic to automagically select Data.Trie if the key is a (strict) bytestring?
I believe this is a key feature of Associated Types: you can create "self-optimizing libraries" that select a different container structure depending on the type. For example, class XMapK k where type XMap k :: * -> * insert :: k -> XMap k v -> XMap k v and then instance XMapK Int where type XMap Int = Data.IntMap.IntMap insert = Data.IntMap.insert etc. Alex

Achim Schneider wrote:
wren ng thornton
wrote: (b) allows instances to have a fixed type for keys (like Data.Trie and Data.IntMap have),
Can't we do some type magic to automagically select Data.Trie if the key is a (strict) bytestring?
Uh, sure. I was thinking more that some ancient proposals for a map interface required that the instance be polymorphic in the keys. Not all maps are polymorphic in the keys, ergo... -- Live well, ~wren
participants (9)
-
Achim Schneider
-
Alexander Dunlap
-
Eugene Kirpichov
-
Jamie Brandon
-
John Meacham
-
Mark Wotton
-
Peter Robinson
-
Svein Ove Aas
-
wren ng thornton