Skip to content
Browse files

added seedIdentity for easier hash consing of types with singletons. …

…breaking api change
  • Loading branch information...
1 parent 3a0a372 commit 7b27952411b2bf202b4e9d5135b960f1feb39848 @ekmett committed
Showing with 7 additions and 4 deletions.
  1. +6 −3 Data/Interned/Internal.hs
  2. +1 −1 intern.cabal
View
9 Data/Interned/Internal.hs
@@ -32,8 +32,9 @@ cacheSize (Cache t) = do
CacheState _ m <- readMVar t
return (HashMap.size m)
-mkCache :: Cache t
-mkCache = Cache $ unsafePerformIO $ newMVar $ CacheState 0 HashMap.empty
+mkCache :: Interned t => Cache t
+mkCache = result where
+ result = Cache $ unsafePerformIO $ newMVar $ CacheState (seedIdentity result) HashMap.empty
type Id = Int
@@ -45,7 +46,9 @@ class ( Eq (Description t)
describe :: Uninterned t -> Description t
identify :: Id -> Uninterned t -> t
identity :: t -> Id
- cache :: Cache t
+ seedIdentity :: p t -> Id
+ seedIdentity _ = 0
+ cache :: Cache t
class Interned t => Uninternable t where
unintern :: t -> Uninterned t
View
2 intern.cabal
@@ -1,6 +1,6 @@
name: intern
category: Data, Data Structures
-version: 0.3.0
+version: 0.4.0
license: BSD3
cabal-version: >= 1.6
license-file: LICENSE

0 comments on commit 7b27952

Please sign in to comment.
Something went wrong with that request. Please try again.