packages feed

fastmemo 0.1.1 → 0.1.2

raw patch · 8 files changed

+48/−33 lines, 8 filesdep +dlistdep ~basedep ~bytestringdep ~containersPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependencies added: dlist

Dependency ranges changed: base, bytestring, containers

API changes (from Hackage documentation)

+ Data.Function.FastMemo: ($dmmemoize) :: (Memoizable a, Generic a, GMemoize (Rep a)) => (a -> b) -> a -> b
- Data.Function.FastMemo: memoize :: (Memoizable a, Generic a, GMemoize (Rep a)) => (a -> b) -> a -> b
+ Data.Function.FastMemo: memoize :: Memoizable a => (a -> b) -> a -> b

Files

fastmemo.cabal view
@@ -1,11 +1,11 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.35.0.+-- This file has been generated from package.yaml by hpack version 0.39.6. -- -- see: https://github.com/sol/hpack  name:           fastmemo-version:        0.1.1+version:        0.1.2 synopsis:       Memoize functions on Generic types description:    Please see the README on GitHub at <https://github.com/davidspies/fastmemo#readme> category:       Memoization@@ -32,6 +32,7 @@       Data.Function.FastMemo.Char       Data.Function.FastMemo.Class       Data.Function.FastMemo.Containers+      Data.Function.FastMemo.DList       Data.Function.FastMemo.Instances       Data.Function.FastMemo.Int       Data.Function.FastMemo.Integer@@ -46,9 +47,10 @@       src   ghc-options: -Wall   build-depends:-      base >=4.7 && <4.18-    , bytestring >=0.10 && <0.12-    , containers ==0.6.*+      base >=4.7 && <4.22+    , bytestring >=0.10 && <0.13+    , containers >=0.6 && <0.9+    , dlist     , utf8-string ==1.0.*     , vector >=0.12 && <0.14   default-language: Haskell2010@@ -64,9 +66,10 @@   ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N   build-depends:       QuickCheck-    , base >=4.7 && <4.18-    , bytestring >=0.10 && <0.12-    , containers ==0.6.*+    , base >=4.7 && <4.22+    , bytestring >=0.10 && <0.13+    , containers >=0.6 && <0.9+    , dlist     , fastmemo     , utf8-string ==1.0.*     , vector >=0.12 && <0.14
src/Data/Function/FastMemo.hs view
@@ -7,6 +7,7 @@ import Data.Function.FastMemo.Char () import Data.Function.FastMemo.Class (Memoizable (..)) import Data.Function.FastMemo.Containers ()+import Data.Function.FastMemo.DList () import Data.Function.FastMemo.Instances () import Data.Function.FastMemo.Int () import Data.Function.FastMemo.Integer ()
+ src/Data/Function/FastMemo/DList.hs view
@@ -0,0 +1,11 @@+{-# LANGUAGE DerivingVia #-}+{-# LANGUAGE StandaloneDeriving #-}+{-# OPTIONS_GHC -Wno-orphans #-}++module Data.Function.FastMemo.DList where++import Data.DList (DList)+import Data.Function.FastMemo.Class (Memoizable)+import Data.Function.FastMemo.List (AsList (..))++deriving via AsList (DList a) instance Memoizable a => Memoizable (DList a)
src/Data/Function/FastMemo/Int.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE DerivingVia #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE StandaloneDeriving #-} {-# OPTIONS_GHC -Wno-orphans #-}@@ -10,20 +11,18 @@ import Data.Int import Data.Word -deriving via IntegralConversion Int Word instance Memoizable Int+deriving via IntegralConversion Word Int instance Memoizable Int -deriving via IntegralConversion Int8 Word8 instance Memoizable Int8+deriving via IntegralConversion Word8 Int8 instance Memoizable Int8 -deriving via IntegralConversion Int16 Word16 instance Memoizable Int16+deriving via IntegralConversion Word16 Int16 instance Memoizable Int16 -deriving via IntegralConversion Int32 Word32 instance Memoizable Int32+deriving via IntegralConversion Word32 Int32 instance Memoizable Int32 -deriving via IntegralConversion Int64 Word64 instance Memoizable Int64+deriving via IntegralConversion Word64 Int64 instance Memoizable Int64 -newtype IntegralConversion a b = IntegralConversion {getIntegralConversion :: a}+newtype IntegralConversion b a = IntegralConversion a+  deriving (Enum, Num, Eq, Ord, Real, Integral) -instance (Integral a, Integral b, Memoizable b) => Memoizable (IntegralConversion a b) where-  memoize f =-    memoize (f . IntegralConversion . fromIntegral)-      . (fromIntegral :: a -> b)-      . getIntegralConversion+instance (Integral a, Integral b, Memoizable b) => Memoizable (IntegralConversion b a) where+  memoize f = memoize (f . fromIntegral) . (fromIntegral :: IntegralConversion b a -> b)
src/Data/Function/FastMemo/Integer.hs view
@@ -18,10 +18,10 @@  integerToSignedNat :: Integer -> (Sign, Natural) integerToSignedNat i-  | i < 0 = (NegativePlus1, fromInteger (- (i + 1)))+  | i < 0 = (NegativePlus1, fromInteger (-(i + 1)))   | otherwise = (NonNegative, fromInteger i)  signedNatToInteger :: (Sign, Natural) -> Integer signedNatToInteger = \case-  (NegativePlus1, n) -> - (toInteger n + 1)+  (NegativePlus1, n) -> -(toInteger n + 1)   (NonNegative, n) -> toInteger n
src/Data/Function/FastMemo/List.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE UndecidableInstances #-} {-# OPTIONS_GHC -Wno-orphans #-} @@ -14,6 +15,7 @@ instance Memoizable a => Memoizable (NonEmpty a)  newtype AsList t = AsList {unAsList :: t}+  deriving (IsList)  instance (IsList t, Memoizable (IsList.Item t)) => Memoizable (AsList t) where-  memoize f = memoize (f . AsList . IsList.fromList) . IsList.toList . unAsList+  memoize f = memoize (f . IsList.fromList) . IsList.toList
src/Data/Function/FastMemo/Util.hs view
@@ -12,7 +12,7 @@ memoizeFixedLen n f   | n <= 0 = const (f [])   | otherwise =-    let f' = memoize $ \x -> memoizeFixedLen (n - 1) (f . (x :))-     in \case-          [] -> error "List too short"-          x : xs -> f' x xs+      let f' = memoize $ \x -> memoizeFixedLen (n - 1) (f . (x :))+       in \case+            [] -> error "List too short"+            x : xs -> f' x xs
src/Data/Function/FastMemo/Word.hs view
@@ -25,19 +25,18 @@  deriving via MemoWord Word64 instance Memoizable Word64 -newtype MemoWord a = MemoWord {getMemoWord :: a}+newtype MemoWord a = MemoWord a  instance (FiniteBits a, Integral a) => Memoizable (MemoWord a) where-  memoize f =-    memoizeFixedLen (byteLen (0 :: a)) (f . MemoWord . fromBytes) . toBytes . getMemoWord+  memoize f = memoizeFixedLen (byteLen (0 :: a)) (f . fromBytes) . toBytes  byteLen :: FiniteBits a => a -> Int byteLen x = (finiteBitSize x + 7) `quot` 8 -toBytes :: (FiniteBits a, Integral a) => a -> [Word8]-toBytes x = [fromIntegral (x `shiftR` i) | i <- [s0, s0 - 8 .. 0]]+toBytes :: (FiniteBits a, Integral a) => MemoWord a -> [Word8]+toBytes (MemoWord x) = [fromIntegral (x `shiftR` i) | i <- [s0, s0 - 8 .. 0]]   where     s0 = (byteLen x - 1) * 8 -fromBytes :: (Bits a, Num a) => [Word8] -> a-fromBytes = foldl' (\acc x -> acc `shiftL` 8 .|. fromIntegral x) 0+fromBytes :: (Bits a, Num a) => [Word8] -> MemoWord a+fromBytes = MemoWord . foldl' (\acc x -> acc `shiftL` 8 .|. fromIntegral x) 0