stable-memo 0.3.1 → 0.4.0
raw patch · 4 files changed
+55/−30 lines, 4 filesdep +taggeddep ~basedep ~ghc-primdep ~hashtables
Dependencies added: tagged
Dependency ranges changed: base, ghc-prim, hashtables
Files
- Data/StableMemo.hs +9/−7
- Data/StableMemo/Internal.hs +10/−6
- Data/StableMemo/Weak.hs +9/−7
- stable-memo.cabal +27/−10
Data/StableMemo.hs view
@@ -60,22 +60,24 @@ > map' (x:xs) = f x : go xs -} -module Data.StableMemo (memo, memo2, memo3, memoPoly) where+module Data.StableMemo (memo, memo2, memo3) where import Control.Applicative import Data.Proxy import qualified Data.StableMemo.Internal as Internal --- | Memoize a function with support for a certain form of polymorphic--- recursion.-memoPoly :: (forall a. f a -> g a) -> f b -> g b-{-# NOINLINE memoPoly #-}-memoPoly = Internal.memo (Proxy :: Proxy Internal.Strong)+-- This is commented out because I now believe it is not safe+--+-- -- | Memoize a function with support for a certain form of polymorphic+-- -- recursion.+-- memoPoly :: (forall a. f a -> g a) -> f b -> g b+-- {-# NOINLINE memoPoly #-}+-- memoPoly = Internal.memo (Proxy :: Proxy Internal.Strong) -- | Memoize a unary function. memo :: (a -> b) -> (a -> b)-memo f = getConst . memoPoly (Const . f . getConst) . Const+memo f = getConst . Internal.memo (Proxy :: Proxy Internal.Strong) (Const . f . getConst) . Const -- | Curried memoization to share partial evaluation memo2 :: (a -> b -> c) -> (a -> b -> c)
Data/StableMemo/Internal.hs view
@@ -1,21 +1,25 @@ {-# LANGUAGE BangPatterns #-}+{-# LANGUAGE CPP #-} {-# LANGUAGE PolyKinds #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE Trustworthy #-} {-# LANGUAGE TypeOperators #-} module Data.StableMemo.Internal (Ref (..), Strong (..), memo) where -import Data.Proxy-import System.Mem.StableName- import Data.HashTable.IO (BasicHashTable)-import GHC.Prim (Any)+import qualified Data.HashTable.IO as HashTable+import Data.Proxy import System.IO.Unsafe (unsafePerformIO)+import System.Mem.StableName import System.Mem.Weak (Weak)+import qualified System.Mem.Weak as Weak import Unsafe.Coerce (unsafeCoerce) -import qualified Data.HashTable.IO as HashTable-import qualified System.Mem.Weak as Weak+#if MIN_VERSION_base(4,10,0)+import GHC.Types (Any)+#else+import GHC.Prim (Any)+#endif newtype (f <<< g) a = O { unO :: f (g a) }
Data/StableMemo/Weak.hs view
@@ -20,7 +20,7 @@ been computed and happens to still be in the heap, it will be reused, otherwise it will be recomputed. -}-module Data.StableMemo.Weak (memo, memo2, memo3, memoPoly) where+module Data.StableMemo.Weak (memo, memo2, memo3) where import Control.Applicative import Data.Proxy@@ -29,15 +29,17 @@ import qualified Data.StableMemo.Internal as Internal --- | Memoize a function with support for a certain form of polymorphic--- recursion.-memoPoly :: (forall a. f a -> g a) -> f b -> g b-{-# NOINLINE memoPoly #-}-memoPoly = Internal.memo (Proxy :: Proxy Weak)+-- This is commented out because I now believe it is not safe+--+-- -- | Memoize a function with support for a certain form of polymorphic+-- -- recursion.+-- memoPoly :: (forall a. f a -> g a) -> f b -> g b+-- {-# NOINLINE memoPoly #-}+-- memoPoly = Internal.memo (Proxy :: Proxy Weak) -- | Memoize a unary function. memo :: (a -> b) -> (a -> b)-memo f = getConst . memoPoly (Const . f . getConst) . Const+memo f = getConst . Internal.memo (Proxy :: Proxy Weak) (Const . f . getConst) . Const -- | Curried memoization to share partial evaluation memo2 :: (a -> b -> c) -> (a -> b -> c)
stable-memo.cabal view
@@ -1,13 +1,28 @@ name: stable-memo-version: 0.3.1+version: 0.4.0 synopsis: Memoization based on argument identity license: MIT license-file: LICENSE author: Jake McArthur <Jake.McArthur@gmail.com> maintainer: Jake McArthur <Jake.McArthur@gmail.com>+homepage: https://github.com/jmcarthur/stable-memo+bug-reports: https://github.com/jmcarthur/stable-memo/issues category: Data build-type: Simple-cabal-version: >=1.18+cabal-version: 1.18+tested-with: GHC ==7.6.3,+ GHC ==7.8.4,+ GHC ==7.10.3,+ GHC ==8.0.2,+ GHC ==8.2.2,+ GHC ==8.4.4,+ GHC ==8.6.5,+ GHC ==8.8.4,+ GHC ==8.10.7,+ GHC ==9.0.2,+ GHC ==9.2.7,+ GHC ==9.4.4,+ GHC ==9.6.1 description: Whereas most memo combinators memoize based on equality, stable-memo@@ -64,9 +79,11 @@ (<http://community.haskell.org/~simonmar/papers/weak.pdf>). library- build-depends: base >=4.6 && <5,- hashtables >=1.0 && <1.3,- ghc-prim >=0.3 && < 0.5+ build-depends: base >=4.6 && <4.19,+ hashtables >=1.0 && <1.4,+ ghc-prim >=0.3 && < 0.11+ if impl(ghc < 8.2)+ build-depends: tagged ==0.7.* default-language: Haskell2010 exposed-modules: Data.StableMemo, Data.StableMemo.Weak other-extensions: BangPatterns,@@ -78,10 +95,10 @@ other-modules: Data.StableMemo.Internal source-repository head- type: darcs- location: http://hub.darcs.net/jmcarthur/stable-memo+ type: git+ location: https://github.com/jmcarthur/stable-memo.git source-repository this- type: darcs- location: http://patch-tag.com/r/jmcarthur/stable-memo- tag: v0.3.1+ type: git+ location: https://github.com/jmcarthur/stable-memo.git+ tag: v0.4.0