cookbook 2.3.2.0 → 2.3.3.0
raw patch · 5 files changed
+49/−38 lines, 5 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Cookbook.Project.Quill.Quill2.Q2Prelude: instance Eq QuillStatus
- Cookbook.Project.Quill.Quill2.Q2Prelude: instance Show QuillStatus
+ Cookbook.Project.Quill.Quill2.Q2Api: qMap :: QuillStatus a -> a
+ Cookbook.Project.Quill.Quill2.Q2Api: qUnsafeExtract :: QuillStatus a -> a
+ Cookbook.Project.Quill.Quill2.Q2Prelude: instance Eq a => Eq (QuillStatus a)
+ Cookbook.Project.Quill.Quill2.Q2Prelude: instance Show a => Show (QuillStatus a)
- Cookbook.Project.Quill.Quill2.Q2Api: addItem :: [Quill] -> QuillAddition -> [Quill]
+ Cookbook.Project.Quill.Quill2.Q2Api: addItem :: [Quill] -> QuillAddition -> QuillStatus [Quill]
- Cookbook.Project.Quill.Quill2.Q2Api: changeItem :: [Quill] -> QuillAddition -> [Quill]
+ Cookbook.Project.Quill.Quill2.Q2Api: changeItem :: [Quill] -> QuillAddition -> QuillStatus [Quill]
- Cookbook.Project.Quill.Quill2.Q2Api: getQuill :: [Quill] -> String -> QuillStatus
+ Cookbook.Project.Quill.Quill2.Q2Api: getQuill :: [Quill] -> String -> QuillStatus Quill
- Cookbook.Project.Quill.Quill2.Q2Api: lookUp :: [Quill] -> (String, String) -> String
+ Cookbook.Project.Quill.Quill2.Q2Api: lookUp :: [Quill] -> (String, String) -> QuillStatus String
- Cookbook.Project.Quill.Quill2.Q2Api: removeItem :: [Quill] -> (String, String) -> [Quill]
+ Cookbook.Project.Quill.Quill2.Q2Api: removeItem :: [Quill] -> (String, String) -> QuillStatus [Quill]
- Cookbook.Project.Quill.Quill2.Q2Io: fromFile :: FilePath -> IO ([Quill])
+ Cookbook.Project.Quill.Quill2.Q2Io: fromFile :: FilePath -> IO [Quill]
- Cookbook.Project.Quill.Quill2.Q2Prelude: QuillMissing :: QuillStatus
+ Cookbook.Project.Quill.Quill2.Q2Prelude: QuillMissing :: String -> QuillStatus a
- Cookbook.Project.Quill.Quill2.Q2Prelude: QuillMultiple :: QuillStatus
+ Cookbook.Project.Quill.Quill2.Q2Prelude: QuillMultiple :: String -> QuillStatus a
- Cookbook.Project.Quill.Quill2.Q2Prelude: QuillSuccess :: Quill -> QuillStatus
+ Cookbook.Project.Quill.Quill2.Q2Prelude: QuillSuccess :: a -> QuillStatus a
- Cookbook.Project.Quill.Quill2.Q2Prelude: data QuillStatus
+ Cookbook.Project.Quill.Quill2.Q2Prelude: data QuillStatus a
Files
- Cookbook/Project/Quill/Quill2/Q2Api.hs +38/−28
- Cookbook/Project/Quill/Quill2/Q2Io.hs +1/−1
- Cookbook/Project/Quill/Quill2/Q2Parse.hs +5/−6
- Cookbook/Project/Quill/Quill2/Q2Prelude.hs +4/−2
- cookbook.cabal +1/−1
Cookbook/Project/Quill/Quill2/Q2Api.hs view
@@ -26,23 +26,24 @@ getQuillBody = snd -- | Find a quill in the database by name, returning it or a possible error type.-getQuill :: [Quill] -> String -> QuillStatus-getQuill [] _ = QuillMissing+getQuill :: [Quill] -> String -> QuillStatus Quill+getQuill [] c = QuillMissing c getQuill (x:xs) c- | Ac.count (map getQuillName (x:xs)) c > 1 = QuillMultiple+ | Ac.count (map getQuillName (x:xs)) c > 1 = QuillMultiple c | getQuillName x == c = QuillSuccess x | otherwise = getQuill xs c -- | Look up the value of a Quill TABLE. Will produce an error on a list.-lookUp :: [Quill] -> (String, String) -> String-lookUp x (a,b) = case (getQuill x a) of- QuillMissing -> error $ "Table not found."- QuillMultiple -> error $ "Multiple values of " ++ a ++ " detected. Database eror, fix manually."+lookUp :: [Quill] -> (String, String) -> QuillStatus String+lookUp x (a,b) = case getQuill x a of (QuillSuccess (c,d)) -> case d of (List f) -> error "Cannot look up the value of a list."- (Table f) -> let c = Lk.lookList f b in if (c == []) then (error $ "Item " ++ b ++ " not found in table " ++ a) else (if (length c > 1) then multipleInnerError else (head c))- where multipleInnerError = error $ "Multiple values of " ++ b ++ " found in table " ++ a ++ ". Database corrupted, change manually."+ (Table f) -> let c = Lk.lookList f b in if null c|| (length c > 1) then QuillMissing b else QuillSuccess $ head c + (QuillMissing _) -> QuillMissing a+ (QuillMultiple _) -> QuillMultiple a+ where multipleInnerError = QuillMultiple b+ -- | Remove a quill from the database by name. removeQuill :: [Quill] -> String -> [Quill] removeQuill [] _ = []@@ -51,46 +52,55 @@ | otherwise = (x,y) : removeQuill xs c -- | Remove an item from a Quill within a database. Works aggressively, meaning it removes all copies to help sanitize QuillMultiples out.-removeItem :: [Quill] -> (String, String) -> [Quill]-removeItem x (a,b) = case (getQuill x a) of+removeItem :: [Quill] -> (String, String) -> QuillStatus [Quill]+removeItem x (a,b) = case getQuill x a of QuillSuccess (c,j) -> case j of- (Table d) -> (c,(Table [(y,t) | (y,t) <- d, y /= b])) : (removeQuill x a)- (List d) -> (c,List $ Ct.remove d c) : removeQuill x a- _ -> (let l = lookUp x (a,b) in x) -- This goes against everything that haskell means.+ (Table d) -> QuillSuccess $ (c, Table [(y,t) | (y,t) <- d, y /= b]) : removeQuill x a+ (List d) -> QuillSuccess $ (c,List $ Ct.remove d c) : removeQuill x a+ QuillMissing _ -> QuillMissing a+ QuillMultiple _ -> QuillMultiple a -- | Adds a Quill databse to the file. addQuill :: [Quill] -> Quill -> [Quill] addQuill x c = c : x -- | Add a QuillAddition to the databse. QuillAddition is a safe encapsulation of list and table values.-addItem :: [Quill] -> QuillAddition -> [Quill]-addItem x qa= case getQuill x a of+addItem :: [Quill] -> QuillAddition -> QuillStatus [Quill]+addItem x qa = case getQuill x a of QuillSuccess (y, ys) -> case ys of (Table d) -> case qa of- (ATable (_,b,c)) -> (y,Table $ (b,c) : d) : removeQuill x a- (AList _ ) -> error $ "$ Type Mismatch! Attempted to add a List type to Table in table " ++ (show qa)+ (ATable (_,b,c)) -> QuillSuccess $ (y,Table $ (b,c) : d) : removeQuill x a+ (AList _ ) -> error $ "$ Type Mismatch! Attempted to add a List type to Table in table " ++ show qa (List d) -> case qa of- (AList (_,b)) -> (y, List $ (b:d)) : removeQuill x a- (ATable _) -> error $ "Type MisMatch! Attempted to add Table type to List in table " ++ (show qa)- QuillMultiple -> error "Multiple found"- QuillMissing -> error "Not found quill!"+ (AList (_,b)) -> QuillSuccess $ (y, List (b:d)) : removeQuill x a+ (ATable _) -> error $ "Type Mismatch! Attempted to add Table type to List in table " ++ show qa+ QuillMultiple v -> QuillMultiple a+ QuillMissing v -> QuillMissing a where a = case qa of (ATable (g,b,c)) -> g (AList (g,b)) -> g +-- | VERY unsafe function. Extracts the value of a QuillStatus, with an error on failure.+qUnsafeExtract :: QuillStatus a -> a+qUnsafeExtract c = case c of+ (QuillSuccess a) -> a+ _ -> error "Generic error in qUnsafeExtract. Do not use this temporary function."++qMap = qUnsafeExtract+ -- | Change an item within the database using a Quill addition. Wrapper of addItem and removeItem.-changeItem :: [Quill] -> QuillAddition -> [Quill]+changeItem :: [Quill] -> QuillAddition -> QuillStatus [Quill] changeItem x y = case y of- (ATable (a,b,c)) -> addItem (removeItem x (a,b)) y- (AList (a,b)) -> addItem (removeItem x (a,b)) y-+ (ATable (a,b,c)) -> addItem (qMap (removeItem x (a,b))) y+ (AList (a,b)) -> addItem (qMap (removeItem x (a,b))) y+ -- | Turn a Quill table into a string. toString :: Quill -> String toString (nm,typ) = case typ of- (List a) -> ("list(" ++ nm ++ "){" ++ (Cm.flt (map (\c -> (c ++ ";")) a))) ++ "}"- (Table a) -> ("table(" ++ nm ++ "){" ++ (Cm.flt $ stringify a)) ++ "}"+ (List a) -> ("list(" ++ nm ++ "){" ++ Cm.flt (map (++ ";") a)) ++ "}"+ (Table a) -> ("table(" ++ nm ++ "){" ++ Cm.flt (stringify a)) ++ "}" where stringify [] = [] stringify ((a,b):xs) = (a ++ ":" ++ b ++ ";") : stringify xs
Cookbook/Project/Quill/Quill2/Q2Io.hs view
@@ -20,7 +20,7 @@ import System.IO -- | Read a Quill database from a file.-fromFile :: FilePath -> IO ([Quill])+fromFile :: FilePath -> IO [Quill] fromFile x = fmap pFile $ Io.filelines x -- | Send a Quill database into a parsable format in a file.
Cookbook/Project/Quill/Quill2/Q2Parse.hs view
@@ -31,12 +31,11 @@ pTable :: String -> Quill pTable x = typ where- name = Md.between (Ct.before x '{') ('(',')') --table(name) or list(name)- typ = (name,if (Ct.before x '{') `Ac.contains` "table" then Table (parseTables body) else List body)- body = Md.splitOn (En.encompassing x ('{','}')) ';'- quoted y = if ('`','\'') `Ac.surrounds` y then En.encompassing x ('`','\'') else Ct.remove y ' '- parseTables [] = []- parseTables (x:xs) =(quoted $ Ct.before x ':', Ct.after x ':') : parseTables xs+ name = Md.between (Ct.before x '{') ('(',')') --table(name) or list(name) gets name.+ typ = (name,if Ct.before x '{' `Ac.contains` "table" then Table (parseTables body) else List body) -- Determines what kind of type the Quill is.+ body = Md.splitOn (En.encompassing x ('{','}')) ';' + quoted y = if ('`','\'') `Ac.surrounds` y then En.encompassing x ('`','\'') else Ct.remove y ' ' -- Whole String encapsulation+ parseTables = map (\x -> (quoted $ Ct.before x ':', Ct.after x ':')) -- | Turn the lines of a file into a list of tables, AKA a Database. pFile :: [String] -> [Quill]
Cookbook/Project/Quill/Quill2/Q2Prelude.hs view
@@ -1,3 +1,6 @@+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE InstanceSigs #-}+{-# LANGUAGE RankNTypes #-} {- | Module : Cookbook.Project.Quill.Quill2.Q2Prelude Copyright : (c) 2014 by Nate Pisarski@@ -17,8 +20,7 @@ type Quill = (String,Element String) -- | Encapsulates errors in the quill database. Currently supports Missing elements and Multiple Instances.-data QuillStatus = QuillSuccess Quill | QuillMissing | QuillMultiple deriving (Eq, Show)+data QuillStatus a = QuillSuccess a | QuillMissing String | QuillMultiple String deriving (Eq, Show)--Find and change these. -- | Safe way of adding items to a Quill database. Allows type-checking on Lists and Tables when manipulating Elements. data QuillAddition = AList (String, String) | ATable (String, String, String) deriving (Eq, Show)-
cookbook.cabal view
@@ -3,7 +3,7 @@ -- PVP summary: +-+------- breaking API changes -- | | +----- non-breaking API additions -- | | | +--- code changes with no API change-version: 2.3.2.0+version: 2.3.3.0 synopsis: Tiered general-purpose libraries with domain-specific applications. description: Cookbook is a line of libraries covering a wide variety of Haskell applications. Every application that I make, I add its functions to Cookbook, turning Cookbook into an all-encompassing general-purpose library over time. The claim-to-fame for the library is its use of overloaded typeclasses, called "Continuities". license: BSD3