EnumSet and EnumMap

I could not quickly find anyone else writing this boiler plate, so I have posted this useful wrapper on the Haskell wiki at http://haskell.org/haskellwiki/EnumSet_EnumMap This uses a cheap newtype to wrap IntSet and IntMap so that you can store any Enum in them. It saves either writing many toEnum/fromEnum functions or using the slower and more generic Data.Set and Data.Map. The original motivation was to go from Map Char to IntMap. And as a bonus, the type signature of the newtype is the same kind as Data.Set and Data.Map (which matters when declaring instances...)
newtype EnumSet e = EnumSet {unEnumSet :: S.IntSet} deriving (Monoid,Eq,Read,Show,Ord)
newtype EnumMap k a = EnumMap {unEnumMap :: M.IntMap a} deriving (Eq,Read,Show,Ord,Monoid,Foldable,Functor)
This has been quickly tested with GHC 6.6 and may contain typographical errors I have not caught yet. -- Chris

On Fri, Feb 23, 2007 at 03:24:27PM +0000, Chris Kuklewicz wrote:
I could not quickly find anyone else writing this boiler plate, so I have posted this useful wrapper on the Haskell wiki at http://haskell.org/haskellwiki/EnumSet_EnumMap
concurrent evolution :) http://repetae.net/repos/jhc/Util/SetLike.hs actually, my 'SetLike' and 'MapLike' typeclasses also defined in that file are quite useful too. John -- John Meacham - ⑆repetae.net⑆john⑈
participants (2)
-
Chris Kuklewicz
-
John Meacham