[Haskell-cafe] two problems with Data.Binary and Data.ByteString

Don Stewart dons at galois.com
Wed Nov 5 14:10:32 EST 2008


kr.angelov:
> On Wed, Aug 13, 2008 at 1:18 AM, Don Stewart <dons at galois.com> wrote:
> >    instance Binary a => Binary [a] where
> >        put l  = put (length l) >> mapM_ put l
> >        get    = do n <- get :: Get Int
> >                    replicateM n get
> 
> Of course I changed this as well. Now it is:
> 
> instance (Ord k, Binary k, Binary e) => Binary (Map.Map k e) where
>     put m = put (Map.size m) >> mapM_ put (Map.toAscList m)
>     get   = liftM Map.fromDistinctAscList get
> 
> You don't have to convert the map to list just to compute its size.
> The Map.size is a O(1) function.

If you have a more efficient instance Binary Map, please send a patch.

Collaborate!

-- Don


More information about the Haskell-Cafe mailing list