pathtype 0.8 → 0.8.1
raw patch · 4 files changed
+39/−7 lines, 4 filesdep +semigroups
Dependencies added: semigroups
Files
- pathtype.cabal +3/−2
- src/System/Path/Internal.hs +17/−4
- src/System/Path/Internal/PartClass.hs +14/−0
- src/System/Path/RegularExpression.hs +5/−1
pathtype.cabal view
@@ -1,5 +1,5 @@ Name: pathtype-Version: 0.8+Version: 0.8.1 Synopsis: Type-safe replacement for System.FilePath etc Description: This package provides type-safe access to filepath manipulations.@@ -71,7 +71,7 @@ Location: http://hub.darcs.net/thielema/pathtype/ Source-Repository this- Tag: 0.8+ Tag: 0.8.1 Type: darcs Location: http://hub.darcs.net/thielema/pathtype/ @@ -90,6 +90,7 @@ deepseq >= 1.3 && <1.5, time >= 1.0 && < 2, transformers >=0.3 && <0.6,+ semigroups >=0.1 && <1.0, tagged >=0.7 && <0.9, base >= 4 && < 5
src/System/Path/Internal.hs view
@@ -116,6 +116,8 @@ fromFileDir, fileFromFileDir, dirFromFileDir,+ toAbsRel,+ fromAbsRel, -- * Path Predicates isAbsolute,@@ -174,6 +176,7 @@ import Data.Maybe (fromMaybe, maybeToList) import Data.Tuple.HT (mapFst, mapSnd) import Data.Monoid (Monoid(mempty, mappend, mconcat), Endo(Endo), appEndo)+import Data.Semigroup (Semigroup(sconcat, (<>)), ) import Data.Char (isSpace) import Data.Ord.HT (comparing) import Data.Eq.HT (equating)@@ -558,10 +561,7 @@ String -> Maybe (Path os ar fd) maybe str = do let (ar0, pcs0, fd0) = untag makePathComponents str- ar <-- case ar0 of- Part.AbsO pc -> Class.switchAbsRel (Just $ Part.Abs pc) Nothing (Just ar0)- Part.RelO -> Class.switchAbsRel Nothing (Just Part.Rel) (Just ar0)+ ar <- Class.fromAbsRel ar0 (pcs, fd) <- case fd0 of Left Part.FileDir -> arrangeComponents pcs0@@ -963,6 +963,12 @@ combineOperator = "</>" +instance (Class.Rel ar, Class.Dir fd) => Semigroup (Path os ar fd) where+ Path r pcs0 _dir <> Path _rel pcs1 d = Path r (pcs0 ++ pcs1) d+ sconcat paths =+ Path Class.relVar+ (sconcat $ fmap (\(Path _rel pcs _dir) -> pcs) paths) Class.dirVar+ instance (Class.Rel ar, Class.Dir fd) => Monoid (Path os ar fd) where mempty = Path Class.relVar [] Class.dirVar mappend (Path r pcs0 _dir) (Path _rel pcs1 d) = Path r (pcs0 ++ pcs1) d@@ -1347,6 +1353,13 @@ dirFromFileDir :: FileDirPath os ar -> DirPath os ar dirFromFileDir (Path ar pcs Part.FileDir) = Path ar pcs Part.Dir+++toAbsRel :: (Class.AbsRel ar) => Path os ar fd -> AbsRelPath os fd+toAbsRel (Path ar pcs fd) = Path (Class.toAbsRel ar) pcs fd++fromAbsRel :: (Class.AbsRel ar) => AbsRelPath os fd -> Maybe (Path os ar fd)+fromAbsRel (Path ar0 pcs fd) = (\ar -> Path ar pcs fd) <$> Class.fromAbsRel ar0 ------------------------------------------------------------------------
src/System/Path/Internal/PartClass.hs view
@@ -112,6 +112,20 @@ isAbsolute :: (AbsRel ar) => ar -> Bool isAbsolute = withAbsRel (const True) False +toAbsRel :: AbsRel ar => ar -> Part.AbsRel+toAbsRel =+ runFuncArg $+ switchAbsRel+ (FuncArg $ \(Part.Abs drive) -> Part.AbsO drive)+ (FuncArg $ \Part.Rel -> Part.RelO)+ (FuncArg id)++fromAbsRel :: AbsRel ar => Part.AbsRel -> Maybe ar+fromAbsRel ar =+ case ar of+ Part.AbsO pc -> switchAbsRel (Just $ Part.Abs pc) Nothing (Just ar)+ Part.RelO -> switchAbsRel Nothing (Just Part.Rel) (Just ar)+ fdMap :: (FileDir fd) => (String -> String) -> fd -> fd fdMap f = appEndo $ switchFileDir (Endo $ Part.fileMap f) (Endo id) (Endo id)
src/System/Path/RegularExpression.hs view
@@ -6,14 +6,18 @@ import qualified Data.List.HT as ListHT import Data.Monoid (Monoid, mempty, mappend)+import Data.Semigroup (Semigroup, (<>)) import Data.Maybe (fromMaybe) newtype Parser a = Parser (MS.StateT [a] Maybe [a]) +instance Semigroup (Parser a) where+ Parser x <> Parser y = Parser $ liftA2 (++) x y+ instance Monoid (Parser a) where mempty = Parser $ return []- mappend (Parser x) (Parser y) = Parser $ liftA2 (++) x y+ mappend = (<>) infixr 5 -|-