Proposal: Value strict versions of containers

Johan Tibell johan.tibell at gmail.com
Mon May 23 14:14:21 CEST 2011


On Mon, May 23, 2011 at 1:31 PM, Sebastian Fischer <fischer at nii.ac.jp> wrote:
> I am also in favour of the "same type approach" because it seems it can help
> to avoid duplicating the implementations. Would it be efficient to define a
> type Data.IntMap.Strict.IntMap with strict fields (also for values) and then
> define Data.IntMap.Lazy in terms of this implementation and a wrapper type?
> data Lazy a = Lazy { getLazy :: a }
> newtype IntMap a = LazyIntMap { getLazyIntMap :: Data.IntMap.Strict (Lazy a)
> }
> lookup :: Int -> IntMap a -> Maybe a
> lookup n = fmap getLazy . Data.IntMap.Strict.lookup n . getLazyIntMap

Not really, it adds two words worth of overhead and one extra indirection.

Johan



More information about the Libraries mailing list