packages feed

dag 0.0.2 → 0.0.2.1

raw patch · 3 files changed

+47/−20 lines, 3 filesdep ~basePVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: base

API changes (from Hackage documentation)

+ Data.Graph.DAG.Edge.Utils: instance Applicative Tree
+ Data.Graph.DAG.Edge.Utils: instance Functor Tree
+ Data.Graph.DAG.Edge.Utils: instance Monad Tree
+ Data.Graph.DAG.Edge.Utils: instance Monoid a => Monoid (Tree a)
- Data.Graph.DAG: GCons :: String -> a -> DAG es a -> DAG es a
+ Data.Graph.DAG: GCons :: String -> a -> (DAG es a) -> DAG es a
- Data.Graph.DAG: GNil :: EdgeSchema es x unique -> DAG es a
+ Data.Graph.DAG: GNil :: (EdgeSchema es x unique) -> DAG es a
- Data.Graph.DAG.Edge.Utils: Node :: a_aa2d -> [Tree a_aa2d] -> Tree a_aa2d
+ Data.Graph.DAG.Edge.Utils: Node :: a_aa2i -> [Tree a_aa2i] -> Tree a_aa2i
- Data.Graph.DAG.Edge.Utils: data NodeSym0 (l_aa2r :: TyFun a_aa2d (TyFun ([] (Tree a_aa2d)) (Tree a_aa2d) -> *))
+ Data.Graph.DAG.Edge.Utils: data NodeSym0 (l_aa2w :: TyFun a_aa2i (TyFun ([] (Tree a_aa2i)) (Tree a_aa2i) -> *))
- Data.Graph.DAG.Edge.Utils: data NodeSym1 (l_aa2u :: a_aa2d) (l_aa2t :: TyFun ([] (Tree a_aa2d)) (Tree a_aa2d))
+ Data.Graph.DAG.Edge.Utils: data NodeSym1 (l_aa2z :: a_aa2i) (l_aa2y :: TyFun ([] (Tree a_aa2i)) (Tree a_aa2i))
- Data.Graph.DAG.Edge.Utils: data Tree a_aa2d
+ Data.Graph.DAG.Edge.Utils: data Tree a_aa2i
- Data.Graph.DAG.Edge.Utils: type NodeSym2 (t_aa2p :: a_aa2d) (t_aa2q :: [] (Tree a_aa2d)) = Node t_aa2p t_aa2q
+ Data.Graph.DAG.Edge.Utils: type NodeSym2 (t_aa2u :: a_aa2i) (t_aa2v :: [] (Tree a_aa2i)) = Node t_aa2u t_aa2v
- Data.Graph.DAG.Edge.Utils: type STree (z_aa2w :: Tree a_aa2d) = Sing z_aa2w
+ Data.Graph.DAG.Edge.Utils: type STree (z_aa2B :: Tree a_aa2i) = Sing z_aa2B

Files

dag.cabal view
@@ -1,5 +1,5 @@ Name:                   dag-Version:                0.0.2+Version:                0.0.2.1 Author:                 Athan Clark <athan.clark@gmail.com> Maintainer:             Athan Clark <athan.clark@gmail.com> License:                BSD3@@ -61,7 +61,7 @@   This library is still very naive, but it will give us compile-time enforcement   of acyclicity (and uniqueness) in these graphs - ideal for dependency graphs. -Cabal-Version:          >= 1.20+Cabal-Version:          >= 1.10 Build-Type:             Simple  Library@@ -71,7 +71,7 @@   Exposed-Modules:      Data.Graph.DAG                         Data.Graph.DAG.Edge                         Data.Graph.DAG.Edge.Utils-  Build-Depends:        base >= 4 && < 5+  Build-Depends:        base >= 4.7 && < 5                       , constraints                       , singletons 
src/Data/Graph/DAG.hs view
@@ -1,7 +1,8 @@ {-# LANGUAGE GADTs #-} {-# LANGUAGE DataKinds #-}-{-# LANGUAGE ExistentialQuantification #-}+{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE ExistentialQuantification #-}  module Data.Graph.DAG         ( module Data.Graph.DAG.Edge@@ -14,31 +15,39 @@ import Data.Graph.DAG.Edge.Utils  import Data.List (lookup)+import Data.Singletons+import Data.Proxy  -- | The graph may be not connected-data DAG es a where-  GNil :: forall es a x unique. EdgeSchema es x unique-       -> DAG es a-  GCons :: String-        -> a -- value-        -> DAG es a-        -> DAG es a-{---- | Convenience function.-getEdgeSchema :: DAG es a -> EdgeSchema es x unique-getEdgeSchema (GNil e) = (e :: EdgeSchema es x unique)-getEdgeSchema (GCons _ _ gs) = getEdgeSchema gs--}+data DAG es a = forall x unique. GNil (EdgeSchema es x unique)+              | GCons String a (DAG es a)+ instance Functor (DAG es) where   fmap f (GNil e) = GNil e   fmap f (GCons k x xs) = GCons k (f x) $     fmap f xs +{-+-- | Convenience function.+-- getEdgeSchema :: DAG es+getEdgeSchema (GNil e) = e+getEdgeSchema (GCons _ _ gs) = getEdgeSchema gs+-}+ -- | A simple @Data.Map.lookup@ duplicate. glookup :: String -> DAG es a -> Maybe a glookup _ (GNil _) = Nothing glookup k (GCons k2 a gs) | k == k2   = Just a                           | otherwise = glookup k gs++-- | Get the spanning trees of an @EdgeSchema@. Operate on the assumtion that+-- the data returned is actually @[Tree String]@.+espanningtrees :: SingI (SpanningTrees' es '[]) =>+                  EdgeSchema es x unique+               -> Demote (SpanningTrees' es '[])+espanningtrees = reflect . getSpanningTrees++-- gspanningtrees   {-
src/Data/Graph/DAG/Edge/Utils.hs view
@@ -2,6 +2,7 @@ {-# LANGUAGE DataKinds #-} {-# LANGUAGE PolyKinds #-} {-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE DeriveFunctor #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE KindSignatures #-} {-# LANGUAGE TemplateHaskell #-}@@ -18,12 +19,29 @@ import Data.Singletons.TH import Data.Singletons.Prelude import Data.Proxy-+import Data.Monoid+import Control.Applicative --- | Trivial rose tree for creating spanning trees+-- | Trivial rose tree for creating spanning trees. We make control structure+-- instances "parallel" (instead of cartesian) by default for simplicity. $(singletons [d|-  data Tree a = Node a [Tree a] deriving (Show, Eq)+  data Tree a = Node a [Tree a] deriving (Show, Eq, Functor)   |])++instance Applicative Tree where+  pure a = Node a []+  (Node f fs) <*> (Node x xs) = Node (f x) $+    zipWith (<*>) fs xs++instance Monad Tree where+  return = pure+  (Node x xs) >>= f = case f x of -- Substitution based instance.+    (Node y ys) -> Node y $ fmap (>>= f) xs++instance Monoid a => Monoid (Tree a) where+  mempty = Node mempty []+  (Node x xs) `mappend` (Node y ys) = Node (x `mappend` y) $+    zipWith mappend xs ys  -- | Gives us a generic way to get our spanning trees of the graph, as a value. -- Credit goes to <stackoverflow.com/questions/28030118/reflecting-heterogeneous-promoted-types-back-to-values-compositionally András Kovács>.