data-inttrie 0.0.9 → 0.1.0
raw patch · 2 files changed
+12/−3 lines, 2 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
+ Data.IntTrie: instance Monoid a => Monoid (BitTrie a)
+ Data.IntTrie: instance Monoid a => Monoid (IntTrie a)
Files
- Data/IntTrie.hs +11/−2
- data-inttrie.cabal +1/−1
Data/IntTrie.hs view
@@ -23,6 +23,7 @@ import Control.Applicative import Data.Bits import Data.Function (fix)+import Data.Monoid (Monoid(..)) -- | A trie from integers to values of type a. -- @@ -38,6 +39,10 @@ pure x = fix (\g -> BitTrie x g g) ~(BitTrie f fl fr) <*> ~(BitTrie x xl xr) = BitTrie (f x) (fl <*> xl) (fr <*> xr) +instance Monoid a => Monoid (BitTrie a) where+ mempty = pure mempty+ mappend = liftA2 mappend+ instance Functor IntTrie where fmap f ~(IntTrie neg z pos) = IntTrie (fmap f neg) (f z) (fmap f pos) @@ -46,16 +51,20 @@ IntTrie fneg fz fpos <*> IntTrie xneg xz xpos = IntTrie (fneg <*> xneg) (fz xz) (fpos <*> xpos) +instance Monoid a => Monoid (IntTrie a) where+ mempty = pure mempty+ mappend = liftA2 mappend+ -- | Apply the trie to an argument. This is the semantic map. apply :: (Ord b, Num b, Bits b) => IntTrie a -> b -> a-apply ~(IntTrie neg z pos) x =+apply (IntTrie neg z pos) x = case compare x 0 of LT -> applyPositive neg (-x) EQ -> z GT -> applyPositive pos x applyPositive :: (Num b, Bits b) => BitTrie a -> b -> a-applyPositive ~(BitTrie one even odd) x+applyPositive (BitTrie one even odd) x | x == 1 = one | testBit x 0 = applyPositive odd (x `shiftR` 1) | otherwise = applyPositive even (x `shiftR` 1)
data-inttrie.cabal view
@@ -1,7 +1,7 @@ Name: data-inttrie Description: A simple lazy, infinite trie from integers.-Version: 0.0.9+Version: 0.1.0 Stability: experimental Synopsis: A lazy, infinite trie of integers. License: BSD3