species 0.3.0.2 → 0.3.1
raw patch · 5 files changed
+98/−40 lines, 5 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Math.Combinatorics.Species: (:*::) :: SizedSpeciesAST f -> SizedSpeciesAST g -> TSpeciesAST (Prod f g)
- Math.Combinatorics.Species: (:+::) :: SizedSpeciesAST f -> SizedSpeciesAST g -> TSpeciesAST (Sum f g)
- Math.Combinatorics.Species: (:.::) :: SizedSpeciesAST f -> SizedSpeciesAST g -> TSpeciesAST (Comp f g)
- Math.Combinatorics.Species: (:><::) :: SizedSpeciesAST f -> SizedSpeciesAST g -> TSpeciesAST (Prod f g)
- Math.Combinatorics.Species: (:@::) :: SizedSpeciesAST f -> SizedSpeciesAST g -> TSpeciesAST (Comp f g)
- Math.Combinatorics.Species: Mu :: Interp f (Mu f) a -> Mu f a
- Math.Combinatorics.Species: TC :: TSpeciesAST Cycle
- Math.Combinatorics.Species: TDer :: SizedSpeciesAST f -> TSpeciesAST (Comp f Star)
- Math.Combinatorics.Species: TE :: TSpeciesAST Set
- Math.Combinatorics.Species: TElt :: TSpeciesAST Id
- Math.Combinatorics.Species: TKSubset :: Integer -> TSpeciesAST Set
- Math.Combinatorics.Species: TL :: TSpeciesAST []
- Math.Combinatorics.Species: TN :: Integer -> TSpeciesAST (Const Integer)
- Math.Combinatorics.Species: TNonEmpty :: SizedSpeciesAST f -> TSpeciesAST f
- Math.Combinatorics.Species: TOfSize :: SizedSpeciesAST f -> (Integer -> Bool) -> TSpeciesAST f
- Math.Combinatorics.Species: TOfSizeExactly :: SizedSpeciesAST f -> Integer -> TSpeciesAST f
- Math.Combinatorics.Species: TOmega :: TSpeciesAST Void
- Math.Combinatorics.Species: TOne :: TSpeciesAST Unit
- Math.Combinatorics.Species: TRec :: f -> TSpeciesAST (Mu f)
- Math.Combinatorics.Species: TSubset :: TSpeciesAST Set
- Math.Combinatorics.Species: TX :: TSpeciesAST Id
- Math.Combinatorics.Species: TZero :: TSpeciesAST Void
- Math.Combinatorics.Species: Wrap :: SizedSpeciesAST s -> ESpeciesAST
- Math.Combinatorics.Species: data Mu f a
- Math.Combinatorics.Species: omega :: (Species s) => s
- Math.Combinatorics.Species: unMu :: Mu f a -> Interp f (Mu f) a
- Math.Combinatorics.Species.AST: unerase :: SpeciesAST -> ESpeciesAST
+ Math.Combinatorics.Species: annotate :: SpeciesAST -> ESpeciesAST
+ Math.Combinatorics.Species: data SpeciesAST
+ Math.Combinatorics.Species: deriveDefaultSpecies :: Name -> Q [Dec]
+ Math.Combinatorics.Species: erase :: ESpeciesAST -> SpeciesAST
+ Math.Combinatorics.Species: erase' :: TSpeciesAST f -> SpeciesAST
+ Math.Combinatorics.Species: newtonRaphson :: (Species s) => s -> Integer -> s
+ Math.Combinatorics.Species: newtonRaphsonRec :: (ASTFunctor f, Species s) => f -> Integer -> Maybe s
+ Math.Combinatorics.Species: simplify :: SpeciesAST -> SpeciesAST
+ Math.Combinatorics.Species: sumOfProducts :: SpeciesAST -> [[SpeciesAST]]
+ Math.Combinatorics.Species: unwrap :: (Typeable1 s) => ESpeciesAST -> TSpeciesAST s
+ Math.Combinatorics.Species: wrap :: (Typeable1 s) => TSpeciesAST s -> ESpeciesAST
+ Math.Combinatorics.Species.AST: annotate :: SpeciesAST -> ESpeciesAST
Files
- CHANGES +4/−0
- Math/Combinatorics/Species.hs +31/−8
- Math/Combinatorics/Species/AST.hs +24/−24
- Math/Combinatorics/Species/Enumerate.hs +38/−7
- species.cabal +1/−1
CHANGES view
@@ -9,3 +9,7 @@ 0.3.0.2 15 July 2010 * General cleanup, and added documentation++0.3.1 18 July 2010+ * rename 'unerase' to the more descriptive 'annotate'+ * export more stuff from Math.Combinatorics.Species and add some docs
Math/Combinatorics/Species.hs view
@@ -27,8 +27,17 @@ module Math.Combinatorics.Species ( -- * The combinatorial species DSL -- $DSL- Species(..) + -- Explicitly export methods of the Species class since+ -- we don't want to export all of them++ Species ( singleton, set, cycle, linOrd+ , subset, ksubset, element+ , o, (><), (@@)+ , ofSize, ofSizeExactly, nonEmpty+ , rec+ )+ -- ** Convenience methods -- $synonyms @@ -74,16 +83,30 @@ -- * Species AST -- $ast- , TSpeciesAST(..)- , ESpeciesAST(..)+ , SpeciesAST , reify , reflect + , TSpeciesAST+ , ESpeciesAST++ , wrap, unwrap+ , erase, erase', annotate++ -- * Species simplification++ , simplify+ , sumOfProducts+ -- * Recursive species -- $rec- , Mu(..), Interp, ASTFunctor(..) + , ASTFunctor(..)+ , newtonRaphsonRec+ , newtonRaphson+ -- * Template Haskell+ , deriveDefaultSpecies , deriveSpecies ) where@@ -96,6 +119,8 @@ import Math.Combinatorics.Species.AST import Math.Combinatorics.Species.AST.Instances import Math.Combinatorics.Species.TH+import Math.Combinatorics.Species.Simplify+import Math.Combinatorics.Species.NewtonRaphson -- $DSL -- The combinatorial species DSL consists of the 'Species' type class,@@ -111,10 +136,8 @@ -- sets@. -- $counting--- XXX -- $enum--- XXX -- $types -- Many of these functors are already defined elsewhere, in other@@ -122,7 +145,7 @@ -- naming/instance schemes, etc., we just redefine them here. -- $ast--- XXX+-- Species expressions can be reified into one of several AST types. -- $rec--- XXX+-- Tools for dealing with recursive species.
Math/Combinatorics/Species/AST.hs view
@@ -33,7 +33,7 @@ -- ** Existentially wrapped AST , ESpeciesAST(..), wrap, unwrap- , erase, erase', unerase+ , erase, erase', annotate -- * ASTFunctor class (codes for higher-order functors) , ASTFunctor(..)@@ -65,7 +65,7 @@ -- | A basic, untyped AST type for species expressions, for easily -- doing things like analysis, simplification, deriving isomorphisms, -- and so on. Converting between 'SpeciesAST' and the typed variant--- 'ESpeciesAST' can be done with 'unerase' and 'erase'.+-- 'ESpeciesAST' can be done with 'annotate' and 'erase'. data SpeciesAST where Zero :: SpeciesAST One :: SpeciesAST@@ -246,37 +246,37 @@ erase' TOmega = Omega -- | Reconstruct the type and interval annotations on a species AST.-unerase :: SpeciesAST -> ESpeciesAST-unerase Zero = wrap TZero-unerase One = wrap TOne-unerase (N n) = wrap (TN n)-unerase X = wrap TX-unerase E = wrap TE-unerase C = wrap TC-unerase L = wrap TL-unerase Subset = wrap TSubset-unerase (KSubset k) = wrap (TKSubset k)-unerase Elt = wrap TElt-unerase (f :+: g) = unerase f + unerase g+annotate :: SpeciesAST -> ESpeciesAST+annotate Zero = wrap TZero+annotate One = wrap TOne+annotate (N n) = wrap (TN n)+annotate X = wrap TX+annotate E = wrap TE+annotate C = wrap TC+annotate L = wrap TL+annotate Subset = wrap TSubset+annotate (KSubset k) = wrap (TKSubset k)+annotate Elt = wrap TElt+annotate (f :+: g) = annotate f + annotate g where Wrap f + Wrap g = wrap $ f :+:: g-unerase (f :*: g) = unerase f * unerase g+annotate (f :*: g) = annotate f * annotate g where Wrap f * Wrap g = wrap $ f :*:: g-unerase (f :.: g) = unerase f . unerase g+annotate (f :.: g) = annotate f . annotate g where Wrap f . Wrap g = wrap $ f :.:: g-unerase (f :><: g) = unerase f >< unerase g+annotate (f :><: g) = annotate f >< annotate g where Wrap f >< Wrap g = wrap $ f :><:: g-unerase (f :@: g) = unerase f @@ unerase g+annotate (f :@: g) = annotate f @@ annotate g where Wrap f @@ Wrap g = wrap $ f :@:: g-unerase (Der f) = der $ unerase f+annotate (Der f) = der $ annotate f where der (Wrap f) = wrap (TDer f)-unerase (OfSize f p) = ofSize $ unerase f+annotate (OfSize f p) = ofSize $ annotate f where ofSize (Wrap f) = wrap $ TOfSize f p-unerase (OfSizeExactly f k) = ofSize $ unerase f+annotate (OfSizeExactly f k) = ofSize $ annotate f where ofSize (Wrap f) = wrap $ TOfSizeExactly f k-unerase (NonEmpty f) = nonEmpty $ unerase f+annotate (NonEmpty f) = nonEmpty $ annotate f where nonEmpty (Wrap f) = wrap $ TNonEmpty f-unerase (Rec f) = wrap $ TRec f-unerase Omega = wrap TOmega+annotate (Rec f) = wrap $ TRec f+annotate Omega = wrap TOmega ------------------------------------------------------------ -- ASTFunctor class --------------------------------------
Math/Combinatorics/Species/Enumerate.hs view
@@ -266,11 +266,11 @@ -- due to the magic of type inference. -- -- For help in knowing what type annotation you can give when--- enumerating the structures of a particular species, see the--- 'structureType' function. To be able to use your own custom data--- type in an enumeration, just make your data type an instance of--- the 'Enumerable' type class; this can be done for you--- automatically by "Math.Combinatorics.Species.TH".+-- enumerating the structures of a particular species at the @ghci@+-- prompt, see the 'structureType' function. To be able to use your+-- own custom data type in an enumeration, just make your data type+-- an instance of the 'Enumerable' type class; this can be done for+-- you automatically by "Math.Combinatorics.Species.TH". -- -- If an invalid type annotation is given, 'enumerate' will call -- 'error' with a helpful error message. This should not be much of@@ -295,7 +295,19 @@ -- all structures built from the given labels. If the type given -- for the enumeration does not match the species expression (via an -- 'Enumerable' instance), call 'error' with an error message--- explaining the mismatch.+-- explaining the mismatch. This is slightly more efficient than+-- 'enumerate' for lists of labels which are known to be distinct,+-- since it doesn't have to waste time checking for+-- duplicates. (However, it probably doesn't really make much+-- difference, since the time to do the actual enumeration will+-- usually dwarf the time to process the list of labels anyway.)+--+-- For example:+--+-- > > enumerateL ballots [1,2,3] :: [Comp [] Set Int]+-- > [[{1,2,3}],[{2,3},{1}],[{1},{2,3}],[{2},{1,3}],[{1,3},{2}],[{3},{1,2}]+-- > ,[{1,2},{3}],[{3},{2},{1}],[{3},{1},{2}],[{2},{3},{1}],[{2},{1},{3}]+-- > ,[{1},{3},{2}],[{1},{2},{3}]] enumerateL :: (Enumerable f, Typeable a) => SpeciesAST -> [a] -> [f a] enumerateL s = enumerateM s . MS.fromDistinctList @@ -307,6 +319,12 @@ -- -- Note that @'enumerateU' s n@ is equivalent to @'enumerate' s -- (replicate n ())@.+--+-- For example:+--+-- > > enumerateU octopi 4 :: [Comp Cycle [] ()]+-- > [<[(),(),(),()]>,<[(),()],[(),()]>,<[(),(),()],[()]>+-- > ,<[(),()],[()],[()]>,<[()],[()],[()],[()]>] enumerateU :: Enumerable f => SpeciesAST -> Int -> [f ()] enumerateU s n = enumerateM s (MS.fromCounts [((),n)]) @@ -316,14 +334,27 @@ -- match the species expression, call 'error' with a message -- explaining the mismatch. enumerateM :: (Enumerable f, Typeable a) => SpeciesAST -> Multiset a -> [f a]-enumerateM s m = map unsafeExtractStructure $ enumerateE (unerase s) m+enumerateM s m = map unsafeExtractStructure $ enumerateE (annotate s) m -- | Lazily enumerate all unlabelled structures.+--+-- For example:+--+-- > > take 10 $ enumerateAllU octopi :: [Comp Cycle [] ()]+-- > [<[()]>,<[(),()]>,<[()],[()]>,<[(),(),()]>,<[(),()],[()]>+-- > ,<[()],[()],[()]>,<[(),(),(),()]>,<[(),()],[(),()]>+-- > ,<[(),(),()],[()]>,<[(),()],[()],[()]>] enumerateAllU :: Enumerable f => SpeciesAST -> [f ()] enumerateAllU s = concatMap (enumerateU s) [0..] -- | Lazily enumerate all labelled structures, using [1..] as the -- labels.+--+-- For example:+--+-- > > take 10 $ enumerateAll ballots :: [Comp [] Set Int]+-- > [[],[{1}],[{1,2}],[{2},{1}],[{1},{2}],[{1,2,3}],[{2,3},{1}]+-- > ,[{1},{2,3}],[{2},{1,3}],[{1,3},{2}]] enumerateAll :: Enumerable f => SpeciesAST -> [f Int] enumerateAll s = concatMap (\n -> enumerateL s (take n [1..])) [0..]
species.cabal view
@@ -1,5 +1,5 @@ name: species-version: 0.3.0.2+version: 0.3.1 license: BSD3 license-file: LICENSE build-type: Simple