packages feed

cookbook 0.1.5.0 → 1.1.0.1

raw patch · 22 files changed

+258/−263 lines, 22 files

Files

− Cookbook/Common.hs
@@ -1,38 +0,0 @@-module Cookbook.Common(sub,positions,pos,apply,flt) where----Cut a list off at a certain point---sub [1,2,3] 1 -> [2 3]--- | Returns a new list starting at a position. List positions start at 0.-sub :: (Eq a) => [a] -> Int -> [a]-sub [] _ = []-sub x 0 = x-sub (x:xs) c = sub xs (c - 1)----Find all positions of an element in a list---positions [1,2,1,2,1,2] 1 -> [ 0 2 4 ]---Edge cases: [] on notElem--- | Finds every occurence of an element within a list, starting at position 0.-positions :: (Eq a) => [a] -> a -> [Int]-positions x c = let y = zip x [0..(length x)] in find y-  where find y = [e | (d,e) <- y, d == c]----Interface to positions to find the first matching element.---pos [1,2,3] 2 -> 1---Edge Cases: -1 on notElem (Maybe unused because this is a helper function)--- | Interface to position for finding the position of the first occurence in a list.-pos :: (Eq a) => [a] -> a -> Int-pos x c | c `notElem` x = -1-pos x c = let ans = positions x c in ((if (length ans) > 1 then (head . tail) else head) ans)----Apply a list of functions to one value.--- | Apply a list of functiosn to one value, using the result from the function beforehand.-apply :: [(a -> a)] -> a -> a-apply [] c = c-apply (f:fs) c = apply fs (f c)---- | Flatten a list one level.-flt :: [[a]] -> [a]-flt [] = []-flt (x:xs) = x ++ flt xs--
− Cookbook/Continuous.hs
@@ -1,41 +0,0 @@-{-# LANGUAGE FlexibleInstances     #-}-{-# LANGUAGE MultiParamTypeClasses #-}--module Cookbook.Continuous(Continuous(..)) where--import Cookbook.Common-import Cookbook.Ingredients.Functional.Break-import Cookbook.Ingredients.Lists.Access---- | 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 $ removeBreak (/=c) x-  before x c  = filterBreak (/=c) x-  delete x c  = filter (/= c) x-  -instance (Eq a) => Continuous [a] [a] where-  after [] _ = []-  after x c-    | take (length c) x == c = sub x ((length c))-    | otherwise = after (tail x) c--  before [] _ = []-  before x c-    | take (length c) x == c = []-    | otherwise = (head x) : before (tail x) c--  delete [] _ = []-  delete x c-    | not (x `contains` c) = x-    | otherwise = (before x c) ++ delete (after x c) c
+ Cookbook/Essential/Common.hs view
@@ -0,0 +1,36 @@+--Cookbook.Essential.Common+--Common is the root of the Cookbook library. It provides the abstracts commonly used to build+--robust applications and sub-libraries within Cookbook. In any Cookbook implementation, Common+--varies based on the language features the language presents. In Haskell, Common merely provides+--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) where++-- | Returns a new list starting at a position. List positions start at 0.+sub :: (Eq a) => [a] -> Int -> [a]+sub [] _ = []+sub x 0 = x+sub (x:xs) c = sub xs (c - 1)++-- | Finds every occurence of an element within a list, starting at position 0.+positions :: (Eq a) => [a] -> a -> [Int]+positions x c = let y = zip x [0..(length x)] in find y+  where find y = [e | (d,e) <- y, d == c]++-- | Interface to position for finding the position of the first occurence in a list.+pos :: (Eq a) => [a] -> a -> Int+pos x c | c `notElem` x = -1+pos x c = let ans = positions x c in ((if (length ans) > 1 then (head . tail) else head) ans)++-- | Apply a list of functiosn to one value, using the result from the function beforehand.+apply :: [(a -> a)] -> a -> a+apply [] c = c+apply (f:fs) c = apply fs (f c)++-- | Flatten a list one level.+flt :: [[a]] -> [a]+flt [] = []+flt (x:xs) = x ++ flt xs++
+ Cookbook/Essential/Continuous.hs view
@@ -0,0 +1,39 @@+{-# LANGUAGE FlexibleInstances     #-}+{-# 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++import qualified Cookbook.Essential.Common as Cm+import qualified Cookbook.Ingredients.Functional.Break as Br+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+  +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++  before [] _ = []+  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
+ Cookbook/Essential/IO.hs view
@@ -0,0 +1,21 @@+--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) where++import  System.IO+import System.Environment++-- | Returns the lines of a file, wrapped in an IO.+filelines :: String -> IO ([String])+filelines x = do+  y <- openFile x ReadMode+  yc <- hGetContents y+  return (lines yc)++-- | Prompts the user for a string+prompt :: String -> IO (String)+prompt x = do+    putStr x+    hFlush stdout+    getLine
− Cookbook/IO.hs
@@ -1,17 +0,0 @@-module Cookbook.IO(filelines,prompt) where-import System.IO-import System.Environment---- | Returns the lines of a file, wrapped in an IO.-filelines :: String -> IO ([String])-filelines x = do-  y <- openFile x ReadMode-  yc <- hGetContents y-  return (lines yc)---- | Prompts the user for a string-prompt :: String -> IO (String)-prompt x = do-    putStr x-    hFlush stdout-    getLine
Cookbook/Ingredients/Functional/Break.hs view
@@ -1,39 +1,25 @@-module Cookbook.Ingredients.Functional.Break(-removeBreak, filterBreak,btr,imbreak) where+--Cookbook.Ingredients.Functional.Break+--Break contains utilities for collectings lists conditionally. Unlike filter +--from prelude, breaks will stop collecting elements of the list at the first+--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. ---Return the list at the first untrue return from predicate f.---removeBreak (==1) [1,1,2,3] -> [2,3]+module Cookbook.Ingredients.Functional.Break(removeBreak, filterBreak,btr,imbreak) where+ -- | When the predicate returns false, removeBreak returns the rest of the list. removeBreak :: (a -> Bool) -> [a] -> [a] removeBreak _ [] = []-removeBreak f (c:cs)-  | not $ f c = (c:cs)-  | otherwise = removeBreak f cs+removeBreak f (c:cs) = if not $ f c then (c:cs) else removeBreak f cs ---Stop consing a list at first untrue return from predicate f.---filterBreak (==1) [1,1,2,3] -> [1,1] -- | When the predicate returns false, filterBreak will stop collecting the list. filterBreak :: (a -> Bool) -> [a] -> [a] filterBreak _ [] = []-filterBreak f (c:cs)-  | not $ f c = []-  | otherwise = c : filterBreak f cs+filterBreak f (c:cs) = if not $ f c then [] else c : filterBreak f cs --- Immediately break out of execution on a true.--- Will return false at the end of execution -- | imbreak will return true if any of the members of the list satisfy the predicate. imbreak :: (a -> Bool) -> [a] -> Bool-imbreak _ [] = False-imbreak f x-  | f (head x) = True-  | otherwise = imbreak f (tail x)+imbreak f = or . map f ---Boolean TRansform: (a,b) a if true, b if not, return the list.---btr (==1) [1,2,3] ('a','b') -> "abb" -- | Conditionally transform input based on the predicate. When it is true, fst of the tupple is used, snd otherwise.-btr :: (a -> Bool) -> [a] -> (b,b) -> [b]-btr _ [] _ = []-btr f (c:cs) (a,b)-  | f c = a : rest-  | otherwise = b : rest-  where rest = btr f cs (a,b)+btr :: (a -> Bool) -> (b,b) -> [a] -> [b]+btr f (a,b) = map (\c -> if f c then a else b)
Cookbook/Ingredients/Lists/Access.hs view
@@ -1,33 +1,31 @@-module Cookbook.Ingredients.Lists.Access(-count,contains,qsort,pull,refpos,areAll) where+--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) where  import qualified Cookbook.Ingredients.Functional.Break as Br -import qualified Cookbook.Common as Cm+import qualified Cookbook.Essential.Common as Cm ---Count the number of occurances in a list.--- | Counts the number of occurences within a list.+-- | Counts the number of occurrences within a list. count :: (Eq a) => [a] -> a -> Int-count x c = sum $ Br.btr (==c) x (1,0)+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-  | (take (length c) x) == c = True-  | otherwise = contains (tail x) c +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  = qsort [y | y <- xs, y <= x]-    greatT = qsort [y | y <- xs, y > x]+  where  (lessT,greatT)  = (qsort $ filter (<=x) xs,qsort $filter (>x) xs) --- | Safe !!+-- | Safer way than (!! (Prelude)) to get items out of a list. Returns nothing on failure. pull :: [a] -> Int -> Maybe a-pull _ (-1) = Nothing+pull _ c | c < 0 = Nothing pull [] _  = Nothing pull (x:xs) c = if c == 0 then (Just x) else pull xs (c - 1) @@ -38,3 +36,7 @@ -- | 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,10 +1,11 @@-module Cookbook.Ingredients.Lists.Modify(-rev,rm,splitOn,snipe,insert) where+--Cookbook.Ingredients.Lists.Modify+--Library for altering the contents of a list. -import qualified Cookbook.Continuous as Cnt-import qualified Cookbook.Common as Com---Reverse a list---rev [1,2,3,4] -> [4,3,2,1]+module Cookbook.Ingredients.Lists.Modify(rev,rm,splitOn,snipe,insert,between) where++import qualified Cookbook.Essential.Continuous as Cnt+import qualified Cookbook.Essential.Common as Cm+ -- | Reverses a list rev :: [a] -> [a] rev [] = []@@ -21,8 +22,16 @@  -- | Change a location in a list with an element. snipe :: (Eq a) => [a] -> (a,Int) -> [a]-snipe x (t,c) = (take c x) ++ [t] ++ (Com.sub x (c + 1))+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 ++ (Com.sub x c)+insert x (t,c) = (take c x) ++ t ++ (Cm.sub x c)++-- | Find out what is in between two elements of a list+between a (c,d) = Cnt.after (Cnt.before a d) c++-- | Intersperse elements into a list.+intersperse :: [a] -> a -> [a]+intersperse [x] _ = [x]+intersperse (x:xs) c =  x:c : intersperse xs c
+ Cookbook/Ingredients/Lists/Replace.hs view
@@ -0,0 +1,31 @@+{-# 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/Stats.hs view
@@ -0,0 +1,14 @@+module Cookbook.Ingredients.Lists.Stats(frequency,mostFrequent) where++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++-- | 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/Ingredients/Tupples/Assemble.hs view
@@ -1,11 +1,15 @@+--Cookbook.Ingredients.Tupples.Assemble+--Assemble is a library for sorting and constructing lists from touples with a member of Ord in the second slot.+--It is used for frequency analyzation, as well as other very particular tasks, but is kept out of Recipes because it is still generic. module Cookbook.Ingredients.Tupples.Assemble(tupsort,assemble) where -+-- | Quicksort a list of tupples, with the (Ord) element being the second one. tupsort :: (Ord b) => [(a,b)] -> [(a,b)] tupsort [] = [] tupsort ((a,n):xs) = lesser ++ [(a,n)] ++ greater   where lesser   = tupsort [(c,d) | (c,d) <- xs, d <= n]         greater = tupsort [(c,d) | (c,d) <- xs, d > n] +-- | Orders element-Ord tupples and gets all of the first elements. assemble :: (Ord b) => [(a,b)] -> [a] assemble = (map fst) . tupsort
Cookbook/Ingredients/Tupples/Look.hs view
@@ -1,17 +1,17 @@+--Cookbook.Ingredients.Tupples.Look+--This library is for manipulating and searching lists of two-element tupples.+ module Cookbook.Ingredients.Tupples.Look(look,lookList,swp) where  -- | Returns the second element of the first tupple where the first element matches input. look :: (Eq a) => [(a,b)] -> a -> (Maybe b) look [] _ = Nothing-look ((a,b):bs) c-  | a == c = (Just b)-  | otherwise = look bs c+look (a:b) c = if fst a == c then Just (snd a) else look b c  -- | Returns all second elements where (fst t) matches the input.-lookList :: (Eq a) => [(a,b)] -> a -> Maybe [b]-lookList d c = case filt of [] -> Nothing ; _ -> Just filt-  where filt = [b | (a,b) <- d, a == c]+lookList :: (Eq a) => [(a,b)] -> a -> [b]+lookList a b =  [d | (c,d) <- a, c == b]  -- | Swap the order of a second-degree tupple. swp :: (a,b) -> (b,a)-swp (a,b) = (b,a)+swp    (a,b)  = (b,a)
+ Cookbook/Project/Configuration/Configuration.hs view
@@ -0,0 +1,6 @@+module Cookbook.Project.Configuration.Configuration(conf) where+import qualified Cookbook.Ingredients.Lists.Modify as Md+import qualified Cookbook.Ingredients.Tupples.Look as Lk++conf :: [String] -> String -> String+conf x c = let configs = [let (d:f:_) = (Md.splitOn y ':') in (d,f)| y <- x, (length y) > 2, ':' `elem` y] in case (Lk.look configs c) of (Just f) -> f;(Nothing) -> []
+ Cookbook/Project/Groups/Groups.hs view
@@ -0,0 +1,21 @@+--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/Recipes/Configuration.hs
@@ -1,8 +0,0 @@-module Cookbook.Recipes.Configuration(conf) where-import Cookbook.Ingredients.Lists.Access-import Cookbook.Ingredients.Lists.Modify-import Cookbook.Ingredients.Tupples.Look--conf :: [String] -> String -> String-conf x c = let configs = [let (d:f:_) = (splitOn y ':') in (d,f)| y <- x, (length y) > 2, ':' `elem` y] in case (look configs c) of (Just f) -> f-                                                                                                                                    (Nothing) -> []
Cookbook/Recipes/Detect.hs view
@@ -1,17 +1,16 @@+--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 Cookbook.Common-import Cookbook.Ingredients.Lists.Access-import Cookbook.Ingredients.Functional.Break+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-  | item `elem` a = (Just b)-  | otherwise = represent c item+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]@@ -25,7 +24,7 @@  -- | Does the string contain the standard strpex pattern? strmatch :: String -> String -> Bool-strmatch x c = (strpex x) `contains` c+strmatch x c = (strpex x) `Ac.contains` c  -- | All lines containing this pattern containingPattern :: [String] -> String -> [String]@@ -34,8 +33,6 @@ -- | All patterns matching the pattern withPattern :: [String] -> String -> [String] withPattern [] _ = []-withPattern a@(x:xs) c-  | strpex takeX == c = takeX : withPattern xs c-  | otherwise = withPattern xs c+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 view
@@ -1,46 +1,16 @@---Library for determining movement of data within a list. ---data Stat can have one of 3 forms:---Less a = Back by a---Even  = Same position---Great a = Forward by a-module Cookbook.Recipes.DiffStat(Stat(..),stat,diff,patch) where--import Cookbook.Common-import Cookbook.Ingredients.Lists.Modify-import Cookbook.Ingredients.Lists.Access-import Cookbook.Ingredients.Tupples.Look--import Data.Maybe-data Stat a = Less a | Even |  Great a deriving (Show)--stat :: (Eq a) => [a] -> [a] -> a -> Stat Int-stat x c f-  | f `notElem` x = error "Unique entry found in stat x"-  | f `notElem` c = error "Unique entry found in stat c"-stat x c f-  | diff < 0  = Less diff-  | diff == 0 = Even-  | otherwise = Great diff-  where diff = (pos x f) - (pos c f)+--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 -diff :: (Eq a) => [a] -> [a] -> [Stat Int]-diff x [] = []-diff x (c:cs) = stat x (c:cs) c : diff x cs+import qualified Cookbook.Essential.Common as  Cm+import qualified Cookbook.Ingredients.Tupples.Assemble as As ---The compiler doesn't like this type signature for some reason.---Here it is anyway, and :t in GHCI can even back it up:---patch :: (Eq a) => [a] -> [Stat Int] -> [Int] -patch x c = assemble $ relatdiff posbind c-  where posbind = zip x [0..((length x))]-        ---Get the absolute positions of diff lists.-relatdiff :: (Eq a) => [(a,Int)] -> [Stat Int] -> [(a,Int)]-relatdiff [] _ = []-relatdiff _ [] = []-relatdiff ((a,b):bs) ((Great x):xs) = (a,(b + x)) : relatdiff bs xs-relatdiff ((a,b):bs) ((Less x):xs) = (a,(b - x)) : relatdiff bs xs-relatdiff ((a,b):bs) ((Even):xs) = (a,(b-1)) : relatdiff bs xs+-- | 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 ---Assemble a relatdiff list-assemble :: [(a,Int)] -> [a]-assemble x = catMaybes $ map (look (map swp x)) $ qsort (map snd x)+-- | 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/Groups.hs
@@ -1,23 +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.Recipes.Groups(Constructor,construct,implement) where--import Cookbook.Ingredients.Lists.Modify-import Cookbook.Ingredients.Lists.Access-import Cookbook.Ingredients.Tupples.Look-import Cookbook.Recipes.Sanitize-import Cookbook.Continuous--type Constructor = (String,[String])----Example: phone:number,name--- | Construct a data constructor. Delmits using '_'-construct :: String -> Constructor-construct x = ((before x ':'),(splitOn (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 (splitOn (after x ':') ',')-  where typ = case look c (before x ':') of (Just e) -> e;  _ -> error "Type undefined."
Cookbook/Recipes/Sanitize.hs view
@@ -2,39 +2,39 @@ --"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 Cookbook.Common-import Cookbook.Ingredients.Lists.Modify-import Cookbook.Ingredients.Lists.Access-import Cookbook.Ingredients.Functional.Break+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  -- | Remove each element of the second list from the first. blacklist :: (Eq a) => [a] -> [a] -> [a]-blacklist x c = apply (map (flip rm) c) x+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 = filterBreak (==c) x+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 (refpos (a,b)) c+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 (refpos (b,a)) c+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 (removeBreak (== x) (y:zs)) else x : rmdb (y:zs)+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 (rm xs x)+rmdbAll (x:xs) = x : rmdb (Md.rm xs x)  --Interface to generic underpinnings 
− Cookbook/Recipes/Stats.hs
@@ -1,14 +0,0 @@-module Cookbook.Recipes.Stats(frequency,mostFrequent) where--import Cookbook.Ingredients.Tupples.Assemble-import Cookbook.Ingredients.Lists.Access-import Cookbook.Ingredients.Lists.Modify-import Cookbook.Recipes.Sanitize---- | 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,count x c)) x in rmdbAll y---- | Get the x amount of most frequent items in the list.-mostFrequent :: (Eq a) => [a] -> Int -> [a]-mostFrequent x c = take c $ rev (assemble  $ frequency x)
cookbook.cabal view
@@ -10,10 +10,10 @@ -- PVP summary:      +-+------- breaking API changes --                   | | +----- non-breaking API additions --                   | | | +--- code changes with no API change-version:             0.1.5.0+version:             1.1.0.1  -- A short (one-line) description of the package.-synopsis:            An independent library of common haskell operations.+synopsis:            A delicious set of interdependant libraries.  -- A longer description of the package. -- description:         @@ -47,7 +47,7 @@  library   -- Modules exported by the library.-  exposed-modules:     Cookbook.Common, Cookbook.Continuous, Cookbook.IO, Cookbook.Recipes.DiffStat, Cookbook.Recipes.Stats, Cookbook.Recipes.Configuration, Cookbook.Ingredients.Functional.Break, Cookbook.Ingredients.Lists.Access, Cookbook.Ingredients.Lists.Modify, Cookbook.Ingredients.Tupples.Look, Cookbook.Ingredients.Tupples.Assemble, Cookbook.Recipes.Detect, Cookbook.Recipes.Groups, Cookbook.Recipes.Sanitize+  exposed-modules:     Cookbook.Essential.Common, Cookbook.Essential.Continuous, Cookbook.Essential.IO, Cookbook.Recipes.DiffStat, Cookbook.Project.Configuration.Configuration, 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.Detect, Cookbook.Project.Groups.Groups, Cookbook.Recipes.Sanitize, Cookbook.Ingredients.Lists.Replace      -- Modules included in this library but not exported.   -- other-modules: