summaryrefslogtreecommitdiff
path: root/src/Storage/Merge.hs
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2022-05-17 22:06:01 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2022-05-17 22:06:01 +0200
commitb8e55c64a68763b0953945476cc75206f5354023 (patch)
tree741f7e66faace0be22ecaa6346f2ca79c045893b /src/Storage/Merge.hs
parentb9e50633254a8c45159a6088309969872b8aae50 (diff)
Mergeable class with separate component type
Diffstat (limited to 'src/Storage/Merge.hs')
-rw-r--r--src/Storage/Merge.hs13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/Storage/Merge.hs b/src/Storage/Merge.hs
index a6ed3ba..6353dad 100644
--- a/src/Storage/Merge.hs
+++ b/src/Storage/Merge.hs
@@ -18,6 +18,7 @@ import Control.Concurrent.MVar
import qualified Data.ByteString.Char8 as BC
import qualified Data.HashTable.IO as HT
+import Data.Kind
import Data.List
import Data.Maybe
import Data.Set (Set)
@@ -29,17 +30,17 @@ import Storage
import Storage.Internal
import Util
-class Storable a => Mergeable a where
- mergeSorted :: [Stored a] -> a
+class Storable (Component a) => Mergeable a where
+ type Component a :: Type
+ mergeSorted :: [Stored (Component a)] -> a
+ toComponents :: a -> [Stored (Component a)]
-merge :: Mergeable a => [Stored a] -> a
+merge :: Mergeable a => [Stored (Component a)] -> a
merge [] = error "merge: empty list"
-merge [x] = fromStored x
merge xs = mergeSorted $ filterAncestors xs
-storeMerge :: Mergeable a => [Stored a] -> IO (Stored a)
+storeMerge :: (Mergeable a, Storable a) => [Stored (Component a)] -> IO (Stored a)
storeMerge [] = error "merge: empty list"
-storeMerge [x] = return x
storeMerge xs@(Stored ref _ : _) = wrappedStore (refStorage ref) $ mergeSorted $ filterAncestors xs
previous :: Storable a => Stored a -> [Stored a]