GTALib 0.0.1 → 0.0.2
raw patch · 2 files changed
+26/−3 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ GTA.Data.JoinList: bagOfNil :: Bag (JoinList a)
+ GTA.Data.JoinList: bagOfSingleton :: a -> Bag (JoinList a)
+ GTA.Data.JoinList: bagUnion :: Bag (JoinList a) -> Bag (JoinList a) -> Bag (JoinList a)
+ GTA.Data.JoinList: crossConcat :: Bag (JoinList a) -> Bag (JoinList a) -> Bag (JoinList a)
+ GTA.Data.JoinList: emptyBag :: Bag (JoinList a)
+ GTA.Data.JoinList: type Semiring a s = GenericSemiring (JoinListAlgebra a) s
Files
- GTALib.cabal +2/−2
- src/GTA/Data/JoinList.hs +24/−1
GTALib.cabal view
@@ -7,7 +7,7 @@ -- The package version. See the Haskell package versioning policy -- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for -- standards guiding when and how versions should be incremented. -Version: 0.0.1 +Version: 0.0.2 -- A short (one-line) description of the package. Synopsis: A library for GTA programming @@ -57,7 +57,7 @@ -- Packages needed in order to build this package. Build-depends: base>=4.3 && < 4.6,template-haskell>=2.5 && <2.8,containers>=0.4 && <0.6,parallel >=3.1 && < 3.3 HS-source-dirs: src/ - --GHC-options: -Wall -O + -- GHC-options: -Wall -O -- Modules not exported by this package. -- Other-modules:
src/GTA/Data/JoinList.hs view
@@ -1,7 +1,8 @@ {-# LANGUAGE MultiParamTypeClasses,FlexibleInstances,FlexibleContexts,FunctionalDependencies,UndecidableInstances,RankNTypes,ExplicitForAll,ScopedTypeVariables,NoMonomorphismRestriction,OverlappingInstances,EmptyDataDecls,RecordWildCards,TypeFamilies,TemplateHaskell #-} -module GTA.Data.JoinList (JoinList(Times, Single, Nil), JoinListAlgebra(JoinListAlgebra), times, single, nil, joinize, dejoinize, segs, inits, tails, subs, assigns, paths, mapJ, count, maxsum, maxsumsolution, maxsumWith, maxsumKWith, maxsumsolutionXKWith, maxsumsolutionXWith, maxsumsolutionWith, maxsumsolutionKWith, maxprodWith, maxprodKWith, maxprodsolutionXKWith, maxprodsolutionXWith, maxprodsolutionWith, maxprodsolutionKWith, segsP, initsP, tailsP, subsP, assignsP) where +module GTA.Data.JoinList (JoinList(Times, Single, Nil), JoinListAlgebra(JoinListAlgebra), times, single, nil, joinize, dejoinize, segs, inits, tails, subs, assigns, paths, mapJ, count, maxsum, maxsumsolution, maxsumWith, maxsumKWith, maxsumsolutionXKWith, maxsumsolutionXWith, maxsumsolutionWith, maxsumsolutionKWith, maxprodWith, maxprodKWith, maxprodsolutionXKWith, maxprodsolutionXWith, maxprodsolutionWith, maxprodsolutionKWith, segsP, initsP, tailsP, subsP, assignsP, crossConcat, bagOfSingleton, emptyBag, bagOfNil, bagUnion, Semiring) where + import GTA.Core import GTA.Util.GenericSemiringStructureTemplate import GTA.Data.BinTree (BinTree (..)) @@ -15,6 +16,7 @@ | Nil -- deriving (Show, Eq, Ord, Read) +-- stupid joinize function joinize :: forall a. [a] -> JoinList a joinize [] = Nil joinize [a] = Single a @@ -23,6 +25,7 @@ d = (n `div` 2) in Times (joinize x1) (joinize x2) +-- stupid dejoinize function dejoinize :: forall a. JoinList a -> [a] dejoinize (Times x1 x2) = dejoinize x1 ++ dejoinize x2 dejoinize (Single a) = [a] @@ -201,3 +204,23 @@ p2 = h (n-1) x2 h _ (Single a) = single a h _ Nil = nil + +--- useful functions to design generators: constructors of bags of lists +crossConcat :: Bag (JoinList a) -> Bag (JoinList a) -> Bag (JoinList a) +crossConcat = times (algebra freeSemiring) + +bagOfSingleton :: a -> Bag (JoinList a) +bagOfSingleton = single (algebra freeSemiring) + +bagOfNil :: Bag (JoinList a) +bagOfNil = nil (algebra freeSemiring) + +emptyBag :: Bag (JoinList a) +emptyBag = let GenericSemiring{..} = freeSemiring :: GenericSemiring (JoinListAlgebra a) (Bag (JoinList a)) + in identity monoid + +bagUnion :: Bag (JoinList a) -> Bag (JoinList a) -> Bag (JoinList a) +bagUnion = let GenericSemiring{..} = freeSemiring :: GenericSemiring (JoinListAlgebra a) (Bag (JoinList a)) + in oplus monoid + +