packages feed

tie-knot 0.1 → 0.2

raw patch · 2 files changed

+18/−18 lines, 2 filesdep +recursion-schemesdep −fixpoint

Dependencies added: recursion-schemes

Dependencies removed: fixpoint

Files

src/Data/Knot.hs view
@@ -21,26 +21,26 @@ -- some kind of keys. The 'tie' function replaces all such references with the actual -- value, creating possibly recursive or cyclic data structures. ----- The module re-exports a part of the fixpoint package.+-- The module re-exports a part of the recursion-schemes package. -- -- An example how to construct a structure with circular dependencies: -- -- > data Person = Person { name :: String, loves :: [Person] } -- > -- Define a variant of Person where the recursive type--- > -- is given as a parameter, and injection/projection functions.--- > instance Fixpoint Person where--- >   data Pre Person t = Loves { _name :: String, _loves :: [t] }--- >   inject ~(Loves n ps)    = Person n ps--- >   project ~(Person n ps)  = Loves n ps+-- > -- is given as a parameter and the embedding function.+-- > data Loves t = Loves { _name :: String, _loves :: [t] }+-- > type instance Base Person = Loves+-- > instance Unfoldable Person where+-- >   embed ~(Loves n ps)    = Person n ps -- > -- > -- The easisest way to get 'Foldable' + 'Functor' is to implement -- > -- 'Traversable' and then just use the default implementations.--- > instance T.Traversable (Pre Person) where+-- > instance T.Traversable Loves where -- >     traverse f (Loves n ns) = Loves n <$> T.traverse f ns -- >--- > instance Functor (Pre Person) where+-- > instance Functor Loves where -- >     fmap = T.fmapDefault--- > instance F.Foldable (Pre Person) where+-- > instance F.Foldable Loves where -- >     foldMap = T.foldMapDefault -- > -- > -- Let's create a person with cicrular dependencies:@@ -53,7 +53,7 @@ -- >           -- you may disagree, but the cat thinks of itself as Person -- >           , Loves "cat"   ["cat"] -- >           ]-module Data.Knot (tie, tie', isConsistent, RefMap, TieError(..), Fixpoint, Pre, inject, project) where+module Data.Knot (tie, tie', isConsistent, RefMap, TieError(..), Base, Unfoldable, embed) where  import Control.Monad import Control.Monad.Error@@ -63,7 +63,7 @@ import Data.Monoid import Data.Maybe -import Data.Fixpoint+import Data.Functor.Foldable  -- | Represents a set of data 'v' that reference each other -- using keys of type 'k'.@@ -88,17 +88,17 @@                                                      else (Just (MissingKey k r)) )  -- | Helper function for anamorphisms.-ana' :: Fixpoint t => (s -> Pre t s) -> Pre t s -> t-ana' f = inject . fmap (ana f)+ana' :: Unfoldable t => (s -> Base t s) -> Base t s -> t+ana' f = embed . fmap (ana f)  -- | Ties the knot without checking consistency. -- If the references are inconsistent, an exception is raised.-tie' :: (Ord k, Fixpoint v) => RefMap k (Pre v) -> Map k v+tie' :: (Ord k, Unfoldable v) => RefMap k (Base v) -> Map k v tie' m = Map.map f m   where     -- (k -> v k) -> v k -> Fix v     f = ana' $ \k -> fromJust (Map.lookup k m)  -- | Checks consistency by calling 'isConsistent' and then and ties the knot using 'tie''.-tie :: (Ord k, F.Foldable (Pre v), Fixpoint v) => RefMap k (Pre v) -> Either (TieError k) (Map k v)+tie :: (Ord k, F.Foldable (Base v), Unfoldable v) => RefMap k (Base v) -> Either (TieError k) (Map k v) tie = liftM tie' . isConsistent
tie-knot.cabal view
@@ -1,5 +1,5 @@ Name:                tie-knot-Version:             0.1+Version:             0.2 Synopsis:     "Ties the knot" on a given set of structures that reference each other by     keys.@@ -8,7 +8,7 @@     keys - replaces the keys with their respective values. Takes @Map k (v k)@     and converts into @Map k v'@ where @v'@ is the fixed point of @v@. See the     homepage for examples.-Category:            Data Structures+Category:            Data Structures, Recursion License:             LGPL License-file:        COPYING.LESSER Author:              Petr Pudlák@@ -25,7 +25,7 @@   location: git://github.com/ppetr/tie-knot.git  Library-  Build-Depends:     base == 4.*, fixpoint >= 0.1.1 && < 2, containers >= 0.4, mtl >= 2+  Build-Depends:     base == 4.*, recursion-schemes == 3.*, containers >= 0.4, mtl >= 2   Exposed-Modules:   Data.Knot   hs-source-dirs:    src --  ghc-options:       -O2