cookbook 2.0.0.1 → 2.1.0.0
raw patch · 23 files changed
+104/−398 lines, 23 files
Files
- Cookbook/Essential/Common.hs +1/−1
- Cookbook/Essential/Continuous.hs +57/−19
- Cookbook/Essential/IO.hs +6/−7
- Cookbook/Ingredients/Functional/Break.hs +1/−6
- Cookbook/Ingredients/Lists/Access.hs +4/−10
- Cookbook/Ingredients/Lists/Modify.hs +9/−15
- Cookbook/Ingredients/Lists/Remove.hs +0/−26
- Cookbook/Ingredients/Lists/Replace.hs +0/−31
- Cookbook/Ingredients/Lists/Splice.hs +0/−14
- Cookbook/Ingredients/Lists/Stats.hs +4/−7
- Cookbook/Project/Configuration/Configuration.hs +1/−1
- Cookbook/Project/Context/Context.hs +0/−33
- Cookbook/Project/Groups/Groups.hs +0/−21
- Cookbook/Project/Preprocess/Preprocess.hs +5/−7
- Cookbook/Project/Quill/Quill.hs +5/−10
- Cookbook/Project/Scribe/Scribe.hs +0/−105
- Cookbook/Recipes/Algorithm.hs +1/−5
- Cookbook/Recipes/DataStructures.hs +1/−2
- Cookbook/Recipes/Detect.hs +0/−38
- Cookbook/Recipes/DiffStat.hs +0/−16
- Cookbook/Recipes/Math.hs +1/−1
- Cookbook/Recipes/Sanitize.hs +5/−20
- cookbook.cabal +3/−3
Cookbook/Essential/Common.hs view
@@ -5,7 +5,7 @@ --informational contexts for modifying/accessing lists. They are placed in this high of a module because --of how ubiquitous their use is, even though they fit in with Cookbook.Ingredients.Lists -module Cookbook.Essential.Common(sub,positions,pos,apply,flt,fromLast) where+module Cookbook.Essential.Common where -- | Returns a new list starting at a position. List positions start at 0. sub :: (Eq a) => [a] -> Int -> [a]
Cookbook/Essential/Continuous.hs view
@@ -2,38 +2,76 @@ {-# LANGUAGE MultiParamTypeClasses #-} --Cookbook.Essential.Continuous---Continuous creates a generic overloaded interface to modify lists.---Making use of generic typeclass constructors, a constraint to the Continuous---typeclass (and thus, the LANGUAGE Pragmas) is not needed.-module Cookbook.Essential.Continuous(Continuous(..)) where+--Continuous is the most important Cookbook library. It defines Overloaded Generic Interfaces+-- (refered to as OGI's throughout the library) for working on two generic types of data, usually+-- lists and items.+module Cookbook.Essential.Continuous where -import qualified Cookbook.Essential.Common as Cm+import qualified Cookbook.Essential.Common as Cm import qualified Cookbook.Ingredients.Functional.Break as Br-import qualified Cookbook.Ingredients.Lists.Access as Ac+import qualified Cookbook.Ingredients.Lists.Access as Ac --- | Continuous provides an interface for function overloading. Everything automatically qualifies to be a constrained by class continuous, so no anotation is required in any type signatures. class Continuous list part where- --- | After returns a sub-list after the first element or first occurence of a larger list. after :: list -> part -> list- --- | Before returns a sub-list before either the first occurence of an element or sublist. before :: list -> part -> list---- | Remove an item from a list, when used on an element, it works the same as rm. delete :: list -> part -> list instance (Eq a) => Continuous [a] a where- after x c = tail $ Br.removeBreak (/=c) x- before x c = Br.filterBreak (/=c) x- delete x c = filter (/= c) x+ after x c = tail $ Br.removeBreak (/=c) x+ before x c = Br.filterBreak (/=c) x+ delete x c = filter (/=c) x instance (Eq a) => Continuous [a] [a] where after [] _ = []- after x c = if Ac.isBefore x c then Cm.sub x (length c) else after (tail x) c+ after x c = if Ac.isBefore x c then Cm.sub x (length c) else after (tail x) c before [] _ = []- before x c = if Ac.isBefore x c then [] else (head x) : before (tail x) c+ before x c = if Ac.isBefore x c then [] else (head x) : before (tail x) c delete [] _ = []- delete x c = if not (x `Ac.contains` c) then x else (before x c) ++ delete (after x c) c+ delete x c = if not (x `Ac.contains` c) then x else (before x c) ++ delete (after x c) c++-- Spliceable+class Splicable a b where+ splice :: a -> b -> a++instance (Eq a) => Splicable [a] (a,a) where+ splice ls (a,b) = before ls a ++ Cm.fromLast ((flip before) b) ls++instance (Eq a) => Splicable [a] ([a],[a]) where+ splice ls (a,b) = before ls a ++ after (after ls a) b++-- Replacable+class Replacable list repls where+ replace :: list -> repls -> list+ +instance (Eq a) => Replacable [a] (a,a) where+ replace lst (on,tw) = map (\c -> if c == on then tw else c) lst+ +instance (Eq a) => Replacable [a] [(a,a)] where+ replace x c = Cm.apply (map (flip replace) c) x+ +instance (Eq a) => Replacable [a] ([a],[a]) where+ replace [] _ = []+ replace lst (on,tw) + | (take (length on) lst) == on = tw ++ replace (Cm.sub lst (length on)) (on,tw)+ | otherwise = (head lst) : replace (tail lst) (on,tw)++instance (Eq a) => Replacable [a] [([a],[a])] where+ replace x c = Cm.apply (map (flip replace) c) x++-- Removable+class Removable list toRm where+ remove :: list -> toRm -> list++instance (Eq a) => Removable [a] a where+ remove x c = [y | y <- x, y /= c]++instance (Eq a) => Removable [a] [a] where+ remove [] _ = []+ remove x@(a:b) c = if take (length c) x == c then remove (restart x) c else a : remove b c+ where restart d = Cm.sub d (length c)++instance (Eq a) => Removable [a] (a,a) where+ remove [] _ = []+ remove (x:xs) (a,b) = if and [x == a, b `elem` xs] then remove (tail (Br.removeBreak (/=b) xs)) (a,b) else x : remove xs (a,b)
Cookbook/Essential/IO.hs view
@@ -1,23 +1,22 @@ --Cookbook.Essential.IO --IO is the only Cookbook library to import System modules. As the name states, Cookbook.IO makes IO --easier and less error-prone by wrapping common IO "gotchas" in a function.-module Cookbook.Essential.IO(filelines,prompt,inhome,getHomePath,filename,modulename) where+module Cookbook.Essential.IO where -import qualified System.IO as LIO-import qualified System.IO.Strict as SIO-import qualified Cookbook.Essential.Continuous as Ct+import qualified System.IO as LIO+import qualified System.IO.Strict as SIO+import qualified Cookbook.Essential.Continuous as Ct import qualified Cookbook.Ingredients.Lists.Modify as Md-import System.Environment++import System.Environment import System.Directory --- | Returns the lines of a file, wrapped in an IO. filelines :: String -> IO ([String]) filelines x = do y <- LIO.openFile x LIO.ReadMode yc <- SIO.hGetContents y return (lines yc) --- | Prompts the user for a string prompt :: String -> IO (String) prompt x = do putStr x
Cookbook/Ingredients/Functional/Break.hs view
@@ -4,26 +4,21 @@ --untrue value. As an addition to this library are functions relating to --mapping predicates over lists to yield either a different result or one solution. -module Cookbook.Ingredients.Functional.Break(removeBreak, filterBreak,btr,imbreak,splitBool) where+module Cookbook.Ingredients.Functional.Break where --- | When the predicate returns false, removeBreak returns the rest of the list. removeBreak :: (a -> Bool) -> [a] -> [a] removeBreak _ [] = [] removeBreak f (c:cs) = if not $ f c then (c:cs) else removeBreak f cs --- | When the predicate returns false, filterBreak will stop collecting the list. filterBreak :: (a -> Bool) -> [a] -> [a] filterBreak _ [] = [] filterBreak f (c:cs) = if not $ f c then [] else c : filterBreak f cs --- | imbreak will return true if any of the members of the list satisfy the predicate. imbreak :: (a -> Bool) -> [a] -> Bool imbreak f = or . map f --- | Conditionally transform input based on the predicate. When it is true, fst of the tupple is used, snd otherwise. btr :: (a -> Bool) -> (b,b) -> [a] -> [b] btr f (a,b) = map (\c -> if f c then a else b)- splitBool :: (Eq a) => (a -> Bool) -> [a] -> [[a]] splitBool _ [] = []
Cookbook/Ingredients/Lists/Access.hs view
@@ -1,43 +1,37 @@ --Cookbook.Ingredients.Lists.Access --Access is a library for generating statistics about a list. The lists are not changed as a result --of executing any Access function.-module Cookbook.Ingredients.Lists.Access(count,contains,qsort,pull,refpos,areAll,isBefore,surrounds) where -import qualified Cookbook.Ingredients.Functional.Break as Br+module Cookbook.Ingredients.Lists.Access where -import qualified Cookbook.Essential.Common as Cm+import qualified Cookbook.Ingredients.Functional.Break as Br+import qualified Cookbook.Ingredients.Tupples.Assemble as As+import qualified Cookbook.Essential.Common as Cm --- | Counts the number of occurrences within a list. count :: (Eq a) => [a] -> a -> Int count x c = sum $ Br.btr (==c) (1,0) x --- | Checks to see if a greater list has a list within it. contains :: (Eq a) => [a] -> [a] -> Bool contains [] _ = False contains x c = if part x == c then True else contains (tail x) c where part = take (length c) --- | Sorts a list from least to greatest. Compose with Cookbook.Ingredients.Lists.Modify.rev for greatest-to-least. qsort :: (Ord a) => [a] -> [a] qsort [] = [] qsort (x:xs) = lessT ++ [x] ++ greatT where (lessT,greatT) = (qsort $ filter (<=x) xs,qsort $filter (>x) xs) --- | Safer way than (!! (Prelude)) to get items out of a list. Returns nothing on failure. pull :: [a] -> Int -> Maybe a pull _ c | c < 0 = Nothing pull [] _ = Nothing pull (x:xs) c = if c == 0 then (Just x) else pull xs (c - 1) --- | Reference an element from one list to another. refpos :: (Eq a) => ([a],[a]) -> a -> a refpos (a,b) c = let d = (pull b (Cm.pos a c)) in case d of (Just x) -> x;(Nothing) -> c --- | Are all elements of the list equal? areAll :: (Eq a) => [a] -> a -> Bool areAll x c = not $ Br.imbreak (/=c) x --- | Is the list a prefix of another? isBefore :: (Eq a) => [a] -> [a] -> Bool isBefore li tf = take (length tf) li == tf
Cookbook/Ingredients/Lists/Modify.hs view
@@ -1,50 +1,40 @@ --Cookbook.Ingredients.Lists.Modify --Library for altering the contents of a list. -module Cookbook.Ingredients.Lists.Modify(rev,rm,splitOn,snipe,insert,between,linesBetween,surroundedBy) where--import qualified Cookbook.Essential.Continuous as Cnt-import qualified Cookbook.Essential.Common as Cm+module Cookbook.Ingredients.Lists.Modify where +import qualified Cookbook.Essential.Continuous as Cnt+import qualified Cookbook.Essential.Common as Cm import qualified Cookbook.Ingredients.Functional.Break as Br-import qualified Cookbook.Ingredients.Lists.Access as Ac+import qualified Cookbook.Ingredients.Lists.Access as Ac --- | Reverses a list rev :: [a] -> [a] rev [] = [] rev (x:xs) = rev xs ++ [x] --- | Removes all occurences from a list.-rm :: (Eq a) => [a] -> a -> [a]+rm :: (Eq a) => [a] -> a -> [a] -- See MDN1 rm x c = filter (/=c) x --- | Create sub-lists based on a delimeter. The string 'joe,joe1,joe2' splitOn ',' would return a list of the three joes. splitOn :: (Eq a) => [a] -> a -> [[a]] splitOn [] _ = [] splitOn x c = if (c `notElem` x) then [x] else (Cnt.before x c) : splitOn (Cnt.after x c) c --- | Change a location in a list with an element. snipe :: (Eq a) => [a] -> (a,Int) -> [a] snipe x (t,c) = (take c x) ++ [t] ++ (Cm.sub x (c + 1)) --- | Snipe, workable with lists and does not delete information. insert :: (Eq a) => [a] -> ([a],Int) -> [a] insert x (t,c) = (take c x) ++ t ++ (Cm.sub x c) --- | Find out what is in between two elements of a list between :: (Eq a) => [a] -> (a,a) -> [a] between a (c,d) = Cnt.after (take (last $ Cm.positions a d) a) c --- | Selectively parse a list based on the existance of a substring. linesBetween :: (Eq a) => [[a]] -> ([a],[a]) -> [[a]] linesBetween a (c,d) = tail $ Br.filterBreak (\e -> not $ Ac.contains e d) $ Br.removeBreak (\e -> not $ Ac.contains e c) a --- | Intersperse elements into a list. intersperse :: [a] -> a -> [a] intersperse [x] _ = [x] intersperse (x:xs) c = x:c : intersperse xs c --- | Perform a function on the last element of a list. onLast :: (a -> a) -> [a] -> [a] onLast _ [] = [] onLast f [x] = f x : []@@ -57,3 +47,7 @@ surroundedBy :: (Eq a) => [a] -> (a,a) -> [[a]] -- Map checks if a or b are not elememts. surroundedBy x (a,b) = if or (map (not . (flip elem) x) [a,b]) then [] else recurse where recurse = Cnt.before (Cnt.after x a) b : surroundedBy (Cnt.after x b) (a,b)++-- [MDN1]+-- This is implemented in Continuous, but is kept here for historical purposes,+-- or for when Continuous is too heavy-duty for whatever job you are on.
− Cookbook/Ingredients/Lists/Remove.hs
@@ -1,26 +0,0 @@---Cookbook.Ingredients.Lists.Remove---Remove is an OGI for removing parts of lists.--{-# LANGUAGE MultiParamTypeClasses #-}-{-# LANGUAGE FlexibleInstances #-}-module Cookbook.Ingredients.Lists.Remove(Removable(..)) where--import Cookbook.Essential.Common as Cm-import Cookbook.Ingredients.Functional.Break as Br-import Cookbook.Ingredients.Lists.Modify as Md--class Removable list toRm where-- remove :: list -> toRm -> list--instance (Eq a) => Removable [a] a where- remove x c = [y | y <- x, y /= c]--instance (Eq a) => Removable [a] [a] where- remove [] _ = []- remove x@(a:b) c = if take (length c) x == c then remove (restart x) c else a : remove b c- where restart d = Cm.sub d (length c)--instance (Eq a) => Removable [a] (a,a) where- remove [] _ = []- remove (x:xs) (a,b) = if and [x == a, b `elem` xs] then remove (tail (Br.removeBreak (/=b) xs)) (a,b) else x : remove xs (a,b)
− Cookbook/Ingredients/Lists/Replace.hs
@@ -1,31 +0,0 @@-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE MultiParamTypeClasses #-}----Cookbook.Ingredients.Lists.Replace---Replace, much alike Cookbook.Essential.Continuous, is a generic overloaded typeclass for replacing parts of lists.---It is overloaded to work with a list and elements, a list and a list of elements, and a list and a list of elements which are lists, and a lists of a lists of elements which are lists.--module Cookbook.Ingredients.Lists.Replace(Replacable(..)) where-import qualified Cookbook.Essential.Common as Cm---- | Provides a generic interface to replacable lists.-class Replacable list repls where---- | Transforms lists of any type.- replace :: list -> repls -> list- -instance (Eq a) => Replacable [a] (a,a) where- replace lst (on,tw) = map (\c -> if c == on then tw else c) lst- -instance (Eq a) => Replacable [a] [(a,a)] where- replace x c = Cm.apply (map (flip replace) c) x- -instance (Eq a) => Replacable [a] ([a],[a]) where- replace [] _ = []- replace lst (on,tw) - | (take (length on) lst) == on = tw ++ replace (Cm.sub lst (length on)) (on,tw)- | otherwise = (head lst) : replace (tail lst) (on,tw)--instance (Eq a) => Replacable [a] [([a],[a])] where- replace x c = Cm.apply (map (flip replace) c) x-
− Cookbook/Ingredients/Lists/Splice.hs
@@ -1,14 +0,0 @@-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE MultiParamTypeClasses #-}-module Cookbook.Ingredients.Lists.Splice(Splicable(..)) where-import qualified Cookbook.Essential.Continuous as Ct-import qualified Cookbook.Essential.Common as Cm--class Splicable a b where- splice :: a -> b -> a--instance (Eq a) => Splicable [a] (a,a) where- splice ls (a,b) = Ct.before ls a ++ Cm.fromLast ((flip Ct.before) b) ls--instance (Eq a) => Splicable [a] ([a],[a]) where- splice ls (a,b) = Ct.before ls a ++ Ct.after (Ct.after ls a) b
Cookbook/Ingredients/Lists/Stats.hs view
@@ -1,15 +1,12 @@-module Cookbook.Ingredients.Lists.Stats(frequency,mostFrequent) where+module Cookbook.Ingredients.Lists.Stats where +import qualified Cookbook.Ingredients.Lists.Access as Ac+import qualified Cookbook.Ingredients.Lists.Modify as Md import qualified Cookbook.Ingredients.Tupples.Assemble as As-import qualified Cookbook.Ingredients.Lists.Access as Ac-import qualified Cookbook.Ingredients.Lists.Modify as Md-import qualified Cookbook.Recipes.Sanitize as Sn+import qualified Cookbook.Recipes.Sanitize as Sn --- | Return a list of all elements of the list with its frequency. frequency :: (Eq a) => [a] -> [(a,Int)] frequency x = let y = map (\c -> (c,Ac.count x c)) x in Sn.rmdbAll y --- | Get the x amount of most frequent items in the list. mostFrequent :: (Eq a) => [a] -> Int -> [a] mostFrequent x c = take c $ Md.rev (As.assemble $ frequency x)-
Cookbook/Project/Configuration/Configuration.hs view
@@ -1,6 +1,6 @@ --Cookbook.Project.Configuration.Configuration (Cf) -- Cf is a library for reading very simple configuration files.-module Cookbook.Project.Configuration.Configuration(conf) where+module Cookbook.Project.Configuration.Configuration where import qualified Cookbook.Ingredients.Lists.Modify as Md import qualified Cookbook.Ingredients.Tupples.Look as Lk
− Cookbook/Project/Context/Context.hs
@@ -1,33 +0,0 @@-module Cookbook.Project.Context.Context(parseContexts,skim) where--import qualified Cookbook.Ingredients.Lists.Modify as Md-import qualified Cookbook.Ingredients.Lists.Access as Ac-import qualified Cookbook.Ingredients.Functional.Break as Br-import qualified Cookbook.Ingredients.Tupples.Look as Lk-import qualified Cookbook.Ingredients.Lists.Replace as Rp--import qualified Cookbook.Essential.IO as CIO--import System.Directory---- Binary search capabilities-skim :: FilePath -> IO [(String,FilePath)]-skim x =- do- allFiles <- getDirectoryContents x- return $ zip (allFiles) (map ((x++"/")++) allFiles)----Helper functions-isGlobalCall x = and [x `Ac.contains` "{=",x `Ac.contains` "=}"]-getGlobalName x = Md.between x ('=','=')---- Parsing-parseContexts :: [(String,String)] -> [String] -> [String] -- Returns a list of shell commands-parseContexts _ [] = []-parseContexts cmdList (line:lines)- | isGlobalCall line = parseGlobal cmdList line (Br.filterBreak notEnd lines) : parseContexts cmdList (Br.removeBreak notEnd lines)- | otherwise = parseContexts cmdList lines- where notEnd = (\c -> not (c `Ac.contains` ("{"++getGlobalName line++"}")))--parseGlobal :: [(String,String)] -> String -> [String] -> String-parseGlobal cmdList header lines = (head $ Lk.lookList cmdList (getGlobalName header)) ++ " " ++ Rp.replace (unlines lines) ('\n',' ')
− Cookbook/Project/Groups/Groups.hs
@@ -1,21 +0,0 @@---Groups is a very small markup language with an inflexible syntax.---Groups have data constructors and implementations.---An example of a groups file can be found in the Examples directory of this repo-module Cookbook.Project.Groups.Groups(Constructor,construct,implement) where--import qualified Cookbook.Ingredients.Lists.Modify as Md-import qualified Cookbook.Ingredients.Tupples.Look as Lk-import qualified Cookbook.Essential.Continuous as Ct--type Constructor = (String,[String])----Example: phone:number,name--- | Construct a data constructor. Delmits using '_'-construct :: String -> Constructor-construct x = ((Ct.before x ':'),(Md.splitOn (Ct.after x ':') '_'))----Example: phone:123-456-7899,Joe--- | Using a list of constructors, implements an instantiation.-implement :: String -> [Constructor] -> [(String,String)]-implement x c = zip typ (Md.splitOn (Ct.after x ':') ',')- where typ = case Lk.look c (Ct.before x ':') of (Just e) -> e; _ -> error "Type undefined."
Cookbook/Project/Preprocess/Preprocess.hs view
@@ -1,21 +1,19 @@ --Cookbook.Project.Preprocess.Preprocess --A library for implementing preprocess syntax, as defined in the .std -module Cookbook.Project.Preprocess.Preprocess(makeParams,gPL) where+module Cookbook.Project.Preprocess.Preprocess where -import qualified Cookbook.Ingredients.Lists.Replace as Rp import qualified Cookbook.Ingredients.Lists.Modify as Md-import qualified Cookbook.Ingredients.Lists.Remove as Rm--import qualified Cookbook.Essential.Common as Cm+import qualified Cookbook.Essential.Common as Cm+import qualified Cookbook.Essential.Continuous as Ct makeParams :: String -> [(String,String)] makeParams x = (flip zip) (repeat lastPart) $ Md.splitOn firstPart '|' where (firstPart:lastPart:[]) = Md.splitOn x '_' sanitize :: String -> String-sanitize x = Rm.remove x ('$','$')+sanitize x = Ct.remove x ('$','$') gPL :: [String] -> [(String,String)] gPL x = Cm.flt $ map makeParams sanitized- where sanitized = Rm.remove (map (\c -> if (length c) > 3 then (sanitize c) else "") x) ""+ where sanitized = Ct.remove (map (\c -> if (length c) > 3 then (sanitize c) else "") x) ""
Cookbook/Project/Quill/Quill.hs view
@@ -1,10 +1,9 @@-module Cookbook.Project.Quill.Quill(tblNames,tables,getTable,lookUp,createTable,removeTable,removeItem,addItem,tableToString,changeItem) where+module Cookbook.Project.Quill.Quill where + import qualified Cookbook.Essential.Common as Cm import qualified Cookbook.Essential.Continuous as Ct-import qualified Cookbook.Ingredients.Lists.Remove as Rm import qualified Cookbook.Ingredients.Lists.Modify as Md import qualified Cookbook.Ingredients.Lists.Access as Ac-import qualified Cookbook.Ingredients.Lists.Splice as Sp import qualified Cookbook.Ingredients.Tupples.Look as Lk import qualified Cookbook.Recipes.Sanitize as Sn @@ -13,7 +12,7 @@ -- Parsing prepare :: [String] -> String-prepare = ((flip Sp.splice) ("(*","*)")) . ((flip Sn.blacklist) [' ','\n']) . Cm.flt+prepare = ((flip Ct.splice) ("(*","*)")) . ((flip Sn.blacklist) ['\n']) . Cm.flt tokenize :: [a] -> [(a,a)] tokenize [] = []@@ -22,15 +21,13 @@ -- Table access tblNames :: String -> [String]-tblNames x = (Ct.before x '{') : Md.surroundedBy x ('}','{')-+tblNames x = (Ct.before x '{') : (tail $ Md.surroundedBy (Sn.blacklist x [' ']) ('}','{')) headlessData :: String -> [[String]] headlessData x = map ((flip Md.splitOn) ';') $ (Md.surroundedBy x ('{','}')) tokenLists :: [[String]] -> [[(String,String)]]-tokenLists x = map tokenize $ map Cm.flt ( map (map ((flip Md.splitOn) ':')) x)-+tokenLists x = ( map (map (\c -> (Ct.before c ':',Ct.after c ':'))) x) -- API functions tables :: [String] -> [(String,[(String,String)])]@@ -65,5 +62,3 @@ tableToString :: (String,[(String,String)]) -> String tableToString (x,b) = x ++ "{" ++ (Cm.flt (map detokenize b)) ++ "}" where detokenize (a,b) = a ++ ":" ++ b ++ ";"--
− Cookbook/Project/Scribe/Scribe.hs
@@ -1,105 +0,0 @@---Cookbook.Project.Scribe---Scribe is a tool for communicating with SCRIBE databases.-module Cookbook.Project.Scribe.Scribe(- Frame(..),Column,Row,Table,Database,- isRow,isColumn,isFrame,isTable,- makeName,- parseFrame,parseColumn,parseRow,parseTable,- readColumn,readRow,readTable,readDatabase,- getTable,getRow,getColumn,getFrame,- qGetRow,qGetColumn,qGetFrame) where--import qualified Cookbook.Essential.Common as Cm-import qualified Cookbook.Essential.Continuous as Ct-import qualified Cookbook.Ingredients.Lists.Modify as Md-import qualified Cookbook.Ingredients.Lists.Access as Ac-import qualified Cookbook.Ingredients.Tupples.Look as Lk-import qualified Cookbook.Ingredients.Functional.Break as Br-import qualified Cookbook.Recipes.Sanitize as St----Data-data Frame = Frame {keyval :: String, entry :: String} | Promise {keyval :: String, link :: String} deriving (Eq,Show)----Type synonyms-type Column = (String,[Frame])-type Row = (String,[Column])-type Table = (String,[Row])-type Database = [Table]----Standard information-isRow x = and [x `Ac.contains` "row", length x > 4]-isColumn x = and [x `Ac.contains` "column", length x > 4]-isFrame x = and $ map ((flip elem) x) "<>"-isTable x = and [x `Ac.contains` "table",length x > 4]--makeName :: String -> String -> String-makeName a b = St.blacklist (Ct.after a b) "{ "----Parsing-parseFrame :: String -> Frame-parseFrame x | not $ isFrame x = error (x ++ " was passed to parseFrame, but does not conform to standard.")-parseFrame x- | ('-','-') `Ac.surrounds` inner = Promise {keyval = Md.between inner ('-','-'), link = Ct.after x '>'}- | otherwise = Frame {keyval = inner, entry = Ct.after x '>'} -- Surrounded in <-->? It's a link.- where inner = Md.between x ('<','>')--parseColumn :: (String,[String]) -> Column -- Expects the column declaration, and the relevant lines.-parseColumn (a,b) = (makeName a "column ",map parseFrame b)--parseRow :: (String,[(String,[String])]) -> Row-parseRow (a,b) = (makeName a "row ",map parseColumn b)--parseTable :: (String,[(String,[(String,[String])])]) -> Table-parseTable (a,b) = (makeName a "table ",map parseRow b)----Reading-readColumn :: [String] -> (String,[String])-readColumn [] = error "Column either does not exist or does not conform to standards."-readColumn (x:xs) | not $ isColumn x = readColumn xs-readColumn (x:xs) = (x,Md.linesBetween (x:xs) ("{","}"))--readRow :: [String] -> (String,[(String,[String])])-readRow [] = error "Row either does not exist or does not conform to standards."-readRow (x:xs) | not $ isRow x = readRow xs-readRow (x:xs) = (x, map readColumn splitup)- where splitup = Br.splitBool (\c -> not $ c `Ac.contains` "}") rowScope- rowScope = Md.linesBetween (x:xs) ("{","}}")--readTable :: [String] -> (String,[(String,[(String,[String])])])-readTable [] = error "Table either does not exist or does not conform to standards."-readTable (x:xs) | not $ isTable x = readTable xs-readTable (x:xs) = (x,map readRow splitup)- where splitup = Br.splitBool (\c -> not $ c `Ac.contains` "}}") tableScope;- tableScope = Md.linesBetween (x:xs) ("{","}}}")----Final functions-readDatabase :: [String] -> Database-readDatabase (x:xs)- | isTable x = parseTable (readTable (x:xs)) : readDatabase (Ct.after xs "}}}")- | otherwise = readDatabase xs----Accessors-getTable :: String -> Database -> Table-getTable a b = (a,(head $ Lk.lookList b a))--getRow :: (String,String) -> Database -> Row-getRow (a,b) c = (b,head $ Lk.lookList (snd (getTable a c)) b)--getColumn :: (String,String,String) -> Database -> Column-getColumn (a,b,c) d = (c,head $ Lk.lookList (snd (getRow (a,b) d)) c)--getFrame :: (String,String,String,String) -> Database -> Frame-getFrame (a,b,c,d) e = let frames = (snd $ getColumn (a,b,c) e) in head $ Lk.lookList (zip (map keyval frames) frames) d----Shorthand accessors-qGetRow :: String -> Database -> Row-qGetRow x z= getRow (a,b) z- where (a,b) = let (f:g:[]) = Md.splitOn x '.' in (f,g)--qGetColumn :: String -> Database -> Column-qGetColumn x z = getColumn (a,b,c) z- where (a,b,c) = let (f:g:h:[]) = Md.splitOn x '.' in (f,g,h)--qGetFrame :: String -> Database -> Frame-qGetFrame x z = getFrame (a,b,c,d) z- where (a,b,c,d) = let (f:g:h:j:[]) = Md.splitOn x '.' in (f,g,h,j)
Cookbook/Recipes/Algorithm.hs view
@@ -1,29 +1,25 @@ --Cookbook.Recipes.Algorithm --Used for traversing data structures.-module Cookbook.Recipes.Algorithm(climb,genMatrix) where+module Cookbook.Recipes.Algorithm where import Cookbook.Recipes.DataStructures import Cookbook.Ingredients.Lists.Modify --- | Gets all the nodes in a binary tree, putting them in a list. climb :: (Tree a) -> [a] climb x = case x of (Empty) -> [];(Branch a (Empty) b) -> a : climb b; (Branch a b (Empty)) -> a : climb b; (Branch a b d) -> a : climb b ++ climb d --- | Provides map-like behavior for binary trees. treeMap :: (Tree a) -> (a -> a) -> (Tree a) treeMap tr f = case tr of Empty -> Empty; (Branch a (Empty) z@(Branch c _ _)) -> (Branch (f c) (treeMap z f) (Empty)); (Branch a z@(Branch b _ _) (Empty)) -> (Branch (f b) (Empty) (treeMap z f)) --- | Provides filter-like behavior for binary trees. treeFilter :: (Tree a) -> (a -> Bool) -> (Tree a) treeFilter Empty f = Empty treeFilter (Branch a (Empty) z@(Branch b _ _)) f = if (f a) then (Branch a (Empty) (treeFilter z f)) else Empty treeFilter (Branch a z@(Branch b _ _) (Empty)) f = if (f a) then (Branch a (treeFilter z f) (Empty)) else Empty --- | Generates a matrix (coord1,coord2,a) with the specified data to null it out. genMatrix :: (Int,Int) -> a -> [((Int,Int),a)] genMatrix (a,b) c = helper (0,0) where helper (d,e)
Cookbook/Recipes/DataStructures.hs view
@@ -1,8 +1,7 @@ --Cookbook.Recipes.DataStructures --Higher-level data structures for use in the rest of Cookbook.-module Cookbook.Recipes.DataStructures(Tree(..),) where+module Cookbook.Recipes.DataStructures where --- | Cookie-cutter implementation of a binary tree. data Tree a = Empty | Branch a (Tree a) (Tree a) deriving (Show)--add a "map" and "filter" function for Tree.
− Cookbook/Recipes/Detect.hs
@@ -1,38 +0,0 @@---Cookbook.Recipes.Detect---Detect is a regex-like library with a defined standard, but in Recipes because it uses generic functions to implement them.--module Cookbook.Recipes.Detect(represent,toRepex,strpex,strmatch,containingPattern,withPattern) where--import Data.Maybe--import qualified Cookbook.Ingredients.Lists.Access as Ac---- | Represent a list using symbols, and if it's not found, return Nothing.-represent :: (Eq a) => [([a],b)] -> a -> (Maybe b)-represent [] _ = Nothing-represent ((a,b):c) item = if item `elem` a then (Just b) else represent c item---- | Filter maybes out, replacing Nothings with a failsafe "catch-all"-toRepex :: (Eq a) => [([a],b)] -> [a] -> b-> [b]-toRepex a b failsafe= map (\c -> case c of (Just x) -> x;_ -> failsafe) (map (represent a) b)----Standardized functions---- | Standard interface to "toRepex" for strings.-strpex :: String -> String-strpex x = toRepex [(['a'..'z'],'@'),(['A'..'Z'],'!'),(['0'..'9'],'#'),([':'..'@']++['\\'..'`']++[' '..'/'],'&')] x '_'---- | Does the string contain the standard strpex pattern?-strmatch :: String -> String -> Bool-strmatch x c = (strpex x) `Ac.contains` c---- | All lines containing this pattern-containingPattern :: [String] -> String -> [String]-containingPattern x c = filter (flip strmatch c) x---- | All patterns matching the pattern-withPattern :: [String] -> String -> [String]-withPattern [] _ = []-withPattern a@(x:xs) c = if strpex takeX == c then takeX : withPattern xs c else withPattern xs c- where takeX = (take (length c) x)-
− Cookbook/Recipes/DiffStat.hs
@@ -1,16 +0,0 @@---Cookbook.Recipes.Diffstat---A library for logging the movements of elements from one equally sized list to another, and patching others.-module Cookbook.Recipes.DiffStat(diff,patch) where--import qualified Cookbook.Essential.Common as Cm-import qualified Cookbook.Ingredients.Tupples.Assemble as As---- | Returns the transpositions each element of a list made.-diff :: (Eq a) => [a] -> [a] -> [Int]-diff a b = map (\(c,d) -> d-c) difflists- where difflists = zip [0..(length a)] (map ( Cm.pos b) a) -- (orignal,new) positions---- | Makes a list out of a difflist-patch :: (Eq a) => [a] -> [Int] -> [a]-patch x c = As.assemble $ zip x (map (\(d,e) -> d+e) ( zip c [0..(length x)]))---Diff returns a relative list. patch has to add the index number of the list to the list to be meaningful in As.assemble
Cookbook/Recipes/Math.hs view
@@ -1,6 +1,6 @@ --Cookbook.Recipes.Math --A library for mathematical formulas, parsing, and conversions.-module Cookbook.Recipes.Math(inc,dec,sqr,avg,stdev,fact) where+module Cookbook.Recipes.Math where --Simple, helper arithmetic functions. inc :: (Num a) => a -> a
Cookbook/Recipes/Sanitize.hs view
@@ -1,57 +1,42 @@-module Cookbook.Recipes.Sanitize(blacklist,rmleading,up,down,rmdb,rmdbAll,tolower,toupper,rmlws,rmsymbols) where+module Cookbook.Recipes.Sanitize where --"Sanization" is quite the overloaded term. The purpose of this sanitzation lib --is to be as unobtrusive yet flexible as possible. This will generally work with --strings, so some domain-specific solutions for strings are present in this lib-import qualified Cookbook.Essential.Common as Cm-import qualified Cookbook.Ingredients.Lists.Modify as Md-import qualified Cookbook.Ingredients.Lists.Access as Ac-import qualified Cookbook.Ingredients.Functional.Break as Br ---Generic Underpinnings+import qualified Cookbook.Essential.Common as Cm+import qualified Cookbook.Ingredients.Lists.Modify as Md+import qualified Cookbook.Ingredients.Lists.Access as Ac+import qualified Cookbook.Ingredients.Functional.Break as Br --- | Remove each element of the second list from the first. blacklist :: (Eq a) => [a] -> [a] -> [a] blacklist x c = Cm.apply (map (flip Md.rm) c) x --- | Remove leading elements from the list. Useful for getting rid of spaces. rmleading :: (Eq a) => [a] -> a -> [a] rmleading x c = Br.filterBreak (==c) x --- | Move an element in one list to the other, if it is not there already. up :: (Eq a) => ([a],[a]) -> [a] -> [a] up (a,b) c = map (Ac.refpos (a,b)) c --- | Up, but down. If that helps. down :: (Eq a) => ([a],[a]) -> [a] -> [a] down (a,b) c = map (Ac.refpos (b,a)) c --- | Remove all adjacent doubles from the list. rmdb :: (Eq a) => [a] -> [a] rmdb [] = [] rmdb [x] = [x] rmdb (x:y:zs) = if x == y then x: rmdb (Br.removeBreak (== x) (y:zs)) else x : rmdb (y:zs) --- | Removes absolutely all doubles, leaving the first copy. rmdbAll :: (Eq a) => [a] -> [a] rmdbAll [] = [] rmdbAll (x:xs) = x : rmdb (Md.rm xs x) ---Interface to generic underpinnings---- | Moves a string to lower case. tolower :: String -> String tolower = down (['a'..'z'],['A'..'Z']) --- | Moves a string to upper case. toupper :: String -> String toupper = up (['a'..'z'],['A'..'Z']) --- | Removes leading whitespace. rmlws :: String -> String rmlws = ((flip rmleading) ' ') --- | Removes all symbols, leaving spaces intact. rmsymbols :: String -> String rmsymbols = ((flip blacklist) (['\\'..'`']))--
cookbook.cabal view
@@ -10,10 +10,10 @@ -- PVP summary: +-+------- breaking API changes -- | | +----- non-breaking API additions -- | | | +--- code changes with no API change-version: 2.0.0.1+version: 2.1.0.0 -- A short (one-line) description of the package.-synopsis: A delicious set of interdependant libraries.+synopsis: Tiered general-purpose libraries with domain-specific applications. -- A longer description of the package. -- description: @@ -48,7 +48,7 @@ library -- Modules exported by the library.- exposed-modules: Cookbook.Project.Context.Context, Cookbook.Essential.Common, Cookbook.Essential.Continuous, Cookbook.Essential.IO, Cookbook.Recipes.DiffStat, Cookbook.Project.Configuration.Configuration, Cookbook.Project.Scribe.Scribe, Cookbook.Project.Preprocess.Preprocess, Cookbook.Ingredients.Functional.Break, Cookbook.Ingredients.Lists.Access, Cookbook.Ingredients.Lists.Remove, Cookbook.Ingredients.Lists.Modify, Cookbook.Ingredients.Lists.Stats, Cookbook.Ingredients.Tupples.Look, Cookbook.Ingredients.Tupples.Assemble, Cookbook.Recipes.Detect, Cookbook.Project.Groups.Groups, Cookbook.Recipes.Sanitize, Cookbook.Ingredients.Lists.Replace, Cookbook.Recipes.Math,Cookbook.Recipes.DataStructures,Cookbook.Recipes.Algorithm, Cookbook.Project.Quill.Quill, Cookbook.Ingredients.Lists.Splice+ exposed-modules: Cookbook.Essential.Common, Cookbook.Essential.Continuous, Cookbook.Essential.IO, Cookbook.Project.Configuration.Configuration, Cookbook.Project.Preprocess.Preprocess, Cookbook.Ingredients.Functional.Break, Cookbook.Ingredients.Lists.Access, Cookbook.Ingredients.Lists.Modify, Cookbook.Ingredients.Lists.Stats, Cookbook.Ingredients.Tupples.Look, Cookbook.Ingredients.Tupples.Assemble, Cookbook.Recipes.Sanitize, Cookbook.Recipes.Math,Cookbook.Recipes.DataStructures,Cookbook.Recipes.Algorithm, Cookbook.Project.Quill.Quill -- Modules included in this library but not exported. -- other-modules: