provenience 0.1.2.4 → 0.2
raw patch · 2 files changed
+49/−21 lines, 2 filesdep ~aesondep ~blaze-markupdep ~containers
Dependency ranges changed: aeson, blaze-markup, containers, data-default, fgl, mtl, pandoc, text, time
Files
- provenience.cabal +16/−16
- src/Control/Provenience.hs +33/−5
provenience.cabal view
@@ -1,5 +1,5 @@ name: provenience-version: 0.1.2.4+version: 0.2 synopsis: Computations that automatically track data dependencies description: see README.md license: GPL-3@@ -12,24 +12,24 @@ build-type: Simple extra-source-files: README.md cabal-version: >=1.10-tested-with: GHC == 7.10.3, GHC == 8.4.4, GHC == 8.6.5, GHC == 8.10.4+tested-with: GHC == 7.10.3, GHC == 8.4.4, GHC == 8.6.5, GHC == 8.10.4, GHC == 9.10.3 library hs-source-dirs: src exposed-modules: Control.Provenience , Data.Representation , Data.Spreadsheet--- tested against stackage lts-6.35 up to lts-16.31+-- tested against stackage lts-6.35 up to lts-24.62 build-depends: base >= 4.7 && < 5- , mtl >= 2.2.1 && <= 2.2.2- , fgl >= 5.5.3.1 && < 5.8- , pandoc >= 1.16 && < 3.0- , blaze-markup >= 0.7.1.1 && < 0.8.3- , aeson >= 0.11.3.0 && < 1.6- , data-default >= 0.5.3 && < 0.8- , containers >= 0.5.6.2 && < 0.7- , time >= 1.5.0.1 && < 2.0- , text >= 1.2.2.2 && < 1.3+ , mtl >= 2.2.1 && < 2.4+ , fgl >= 5.5.3.1 && < 5.9+ , pandoc >= 1.16 && < 3.9+ , blaze-markup >= 0.7.1.1 && < 0.9+ , aeson >= 0.11.3.0 && < 2.3+ , data-default >= 0.5.3 && < 0.9+ , containers >= 0.5.6.2 && < 0.8+ , time >= 1.5.0.1 && < 1.13+ , text >= 1.2.2.2 && < 2.2 default-language: Haskell2010 other-extensions: CPP @@ -44,10 +44,10 @@ buildable: False build-depends: base >= 4.7 && < 5 , provenience- , mtl >= 2.2.1 && <= 2.2.2- , pandoc >= 1.16 && < 3.0- , text >= 1.2.2.2 && < 2.0- , data-default >= 0.5.3 && < 0.8+ , mtl >= 2.2.1 && < 2.4+ , pandoc >= 1.16 && < 3.9+ , text >= 1.2.2.2 && < 2.2+ , data-default >= 0.5.3 && < 0.9 , containers , doctemplates
src/Control/Provenience.hs view
@@ -57,7 +57,7 @@ separated by blank rows. -} -{-# LANGUAGE CPP,MultiParamTypeClasses,FlexibleInstances,FlexibleContexts,OverloadedStrings,Rank2Types,ScopedTypeVariables #-} +{-# LANGUAGE CPP,MultiParamTypeClasses,FlexibleInstances,FlexibleContexts,OverloadedStrings,Rank2Types,ScopedTypeVariables,DeriveFunctor,PatternSynonyms #-} module Control.Provenience ( -- * Variables Variable,value @@ -130,7 +130,8 @@ description :: Block, -- ^ a description explaining the content valueRendering :: Block, -- ^ a rendering of the 'Variable's 'value' altRep :: alt -- ^ alternative representation - } + } deriving (Functor) + -- | Variables are internally numbered by 'Node' = 'Int' -- and have an alternative value 'Representation' @alt@. -- Further each variable has a Pandoc 'description' (set by '<?') @@ -138,7 +139,28 @@ -- to be used in hyperlinks. data VariableStore alt = VariableStore { dependencyGraph :: Gr (VariableDesc alt) Block, - nextFreeNode :: Node} + nextFreeNode :: Node -- greater than any node in the dependency graph + } +instance Functor VariableStore where + fmap f store = store { + dependencyGraph = nmap (fmap f) (dependencyGraph store) + } +-- | disjoint union +instance Semigroup (VariableStore alt) where + store1 <> store2 = let + nodeOffset :: Node -> Node + nodeOffset = (+) (nextFreeNode store1) + offsetAdj :: Adj b -> Adj b + offsetAdj = (fmap.fmap) nodeOffset + offsetCtxt :: Context a b -> Context a b + offsetCtxt (incoming,n,a,outgoing) = (offsetAdj incoming,nodeOffset n,a,offsetAdj outgoing) + disjointUnion g1 g2 = ufold (\ct g -> insert (offsetCtxt ct) g) g1 g2 + in VariableStore { + dependencyGraph = dependencyGraph store1 `disjointUnion` dependencyGraph store2, + nextFreeNode = nodeOffset (nextFreeNode store2) + } +instance Monoid (VariableStore alt) where + mempty = VariableStore empty 0 -- | Obtain a graph of all the 'Variable's alternative representations graphAltReps :: VariableStore alt -> Gr alt Block @@ -255,6 +277,12 @@ divVars (n0,n1) = Div ("variables"++(showHex n0 ("To"++(showHex n1 ""))),["provenienceVariables"],[]) #endif +-- pandoc-types >= 1.23 removed the Null constructor +#if MIN_VERSION_pandoc(3,0,0) +pattern Null :: Block +pattern Null = Plain [] +#endif + -- | Use the 'show' method to render a 'value' as 'Plain' text. renderShow :: Show a => a -> Block renderShow = Plain . inlinesString . show @@ -368,7 +396,7 @@ v <- fmap (Variable i) a let desc = VariableDesc { shortname = Nothing, - description = Null, + description = Null, -- Note: Null constructor is removed in pandoc-types-1.23 (pandoc >= 3.0) valueRendering = Null, altRep = error "no alternative representation supplied" } @@ -466,7 +494,7 @@ -- which is not worth registering a 'Variable' for. (<%?>) :: Monad m => ProvenienceT alt m (a -> b) -> Either a (Variable a) -> ProvenienceT alt m b pf <%?> (Right px) = pf <%> px -pf <%?> (Left x) = (fmap.fmap) ($x) pf +pf <%?> (Left x) = (fmap.fmap) ($ x) pf -- | Like above but permit side-effects in the base monad. (<%%>) :: Monad m => ProvenienceT alt m (a -> m b) -> Variable a -> ProvenienceT alt m b