packages feed

monopati 0.1.1 → 0.1.2

raw patch · 6 files changed

+203/−66 lines, 6 filesdep +directoryPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependencies added: directory

API changes (from Hackage documentation)

- System.Monopati.Posix: instance GHC.Show.Show (System.Monopati.Posix.Outline 'System.Monopati.Posix.Home 'System.Monopati.Posix.Directory)
- System.Monopati.Posix: instance GHC.Show.Show (System.Monopati.Posix.Outline 'System.Monopati.Posix.Home 'System.Monopati.Posix.File)
- System.Monopati.Posix: instance GHC.Show.Show (System.Monopati.Posix.Outline 'System.Monopati.Posix.Root 'System.Monopati.Posix.Directory)
- System.Monopati.Posix: instance GHC.Show.Show (System.Monopati.Posix.Outline 'System.Monopati.Posix.Root 'System.Monopati.Posix.File)
- System.Monopati.Posix: instance GHC.Show.Show (System.Monopati.Posix.Outline 'System.Monopati.Posix.Vague 'System.Monopati.Posix.Directory)
- System.Monopati.Posix: instance GHC.Show.Show (System.Monopati.Posix.Outline 'System.Monopati.Posix.Vague 'System.Monopati.Posix.File)
+ System.Monopati.Posix: change :: Absolute Path To Directory -> IO ()
+ System.Monopati.Posix: create :: Absolute Path To Directory -> IO ()
+ System.Monopati.Posix: current :: IO (Maybe (Absolute Path To Directory))
+ System.Monopati.Posix: deeper :: Relative Path To points -> Maybe (Relative Path To points)
+ System.Monopati.Posix: home :: IO (Maybe (Absolute Path To Directory))
+ System.Monopati.Posix: parent :: Absolute Path To points -> Maybe (Absolute Path To Directory)
+ System.Monopati.Posix: remove :: Absolute Path To Directory -> IO ()

Files

System/Monopati/Posix.hs view
@@ -1,63 +1,9 @@-module System.Monopati.Posix where--import "base" Data.Eq (Eq ((==)))-import "base" Data.Foldable (Foldable (foldr))-import "base" Data.Function ((.), ($), flip)-import "base" Data.Kind (Type)-import "base" Data.List (filter, init)-import "base" Data.Maybe (Maybe (Just, Nothing))-import "base" Data.Semigroup (Semigroup ((<>)))-import "base" Data.String (String)-import "base" Text.Show (Show (show))-import "free" Control.Comonad.Cofree (Cofree ((:<)))--data Points = Directory | File -- What the path points to?-data Origin = Root | Home | Vague -- What is the beginning of the path?-data To -- Dummy type needed only for beauty type declarations--type Path = Cofree Maybe String---- | The internal type of path representation-newtype Outline (origin :: Origin) (points :: Points) = Outline { outline :: Path }--instance Show (Outline Root Directory) where-	show = flip (<>) "/" . foldr (\x acc -> acc <> "/" <> x) "" . outline--instance Show (Outline Root File) where-	show = foldr (\x acc -> acc <> "/" <> x) "" . outline--instance Show (Outline Home Directory) where-	show = (<>) "~/" . foldr (\x acc -> x <> "/" <> acc) "" . outline--instance Show (Outline Home File) where-	show = (<>) "~/" . init . foldr (\x acc -> x <> "/" <> acc) "" . outline--instance Show (Outline Vague Directory) where-	show = foldr (\x acc -> x <> "/" <> acc) "" . outline--instance Show (Outline Vague File) where-	show = init . foldr (\x acc -> x <> "/" <> acc) "" . outline--type family Absolute (path :: Type) (to :: Type) (points :: Points) :: Type where-	Absolute Path To points = Outline Root points--type family Homeward (path :: Type) (to :: Type) (points :: Points) :: Type where-	Homeward Path To points = Outline Home points--type family Relative (path :: Type) (to :: Type) (points :: Points) :: Type where-	Relative Path To points = Outline Vague points--part :: String -> Outline origin points-part x = Outline $ (filter (== '/') x) :< Nothing--(<^>) :: Relative Path To Directory -> Relative Path To points -> Relative Path To points-Outline (x :< Nothing) <^> Outline that = Outline $ x :< Just that-Outline (x :< Just this) <^> Outline that = part x <^> (Outline this <^> Outline that)--(</>) :: Absolute Path To Directory -> Relative Path To points -> Absolute Path To points-Outline absolute </> Outline (x :< Nothing) = Outline . (:<) x . Just $ absolute-Outline absolute </> Outline (x :< Just xs) = (Outline . (:<) x . Just $ absolute) </> Outline xs+module System.Monopati.Posix (+	-- * CRUD operations for filesystem+	module System.Monopati.Posix.Calls,+	-- * Pure combinators+	module System.Monopati.Posix.Combinators+	) where -(<~/>) :: Absolute Path To points -> Homeward Path To points -> Absolute Path To points-Outline absolute <~/> Outline (x :< Nothing) = Outline . (:<) x . Just $ absolute-Outline absolute <~/> Outline (x :< Just xs) = (Outline . (:<) x . Just $ absolute) <~/> Outline xs+import System.Monopati.Posix.Calls+import System.Monopati.Posix.Combinators
+ System/Monopati/Posix/Calls.hs view
@@ -0,0 +1,43 @@+module System.Monopati.Posix.Calls (current, home, create, change, remove) where++import "base" Data.Bool (Bool (True))+import "base" Data.Foldable (Foldable (foldr))+import "base" Data.Function ((.), ($))+import "base" Data.Functor ((<$>))+import "base" Data.List (tail, reverse)+import "base" Data.Maybe (Maybe (Just, Nothing))+import "base" Data.String (String)+import "base" System.IO (IO)+import "base" Text.Show (show)+import "directory" System.Directory (createDirectoryIfMissing, getCurrentDirectory+	, getHomeDirectory, removeDirectoryRecursive, setCurrentDirectory)+import "free" Control.Comonad.Cofree (Cofree ((:<)))+import "split" Data.List.Split (splitOn)++import System.Monopati.Posix.Combinators (Points (Directory), To, Path, Origin (Root), Outline (Outline), Absolute, Homeward, Relative)++-- | Return Nothing, if current working directory is root (cwd)+current :: IO (Maybe (Absolute Path To Directory))+current = parse <$> getCurrentDirectory++-- | Retrieve absolute path of home directory (echo ~)+home :: IO (Maybe (Absolute Path To Directory))+home = parse <$> getHomeDirectory++parse :: String -> Maybe (Absolute Path To Directory)+parse "/" = Nothing+parse directory = (<$>) Outline+	. foldr (\el -> Just . (:<) el) Nothing+	. reverse . splitOn "/" . tail $ directory++-- | Create a directory (mkdir)+create :: Absolute Path To Directory -> IO ()+create = createDirectoryIfMissing True . show++-- | Change directory (cd)+change :: Absolute Path To Directory -> IO ()+change = setCurrentDirectory . show++-- | Remove directory (rm -rf)+remove :: Absolute Path To Directory -> IO ()+remove = removeDirectoryRecursive . show
+ System/Monopati/Posix/Combinators.hs view
@@ -0,0 +1,131 @@+module System.Monopati.Posix.Combinators+	( Points (..), Origin (..), To, Path, Outline (..)+	, Absolute (..), Homeward (..), Relative (..)+	, deeper, part, parent, (<^>), (</>), (<~/>)) where++import "base" Control.Applicative (pure)+import "base" Data.Eq (Eq ((==)))+import "base" Data.Foldable (Foldable (foldr))+import "base" Data.Function ((.), ($), (&), flip)+import "base" Data.Functor ((<$>))+import "base" Data.Kind (Type)+import "base" Data.List (filter, init)+import "base" Data.Maybe (Maybe (Just, Nothing), maybe)+import "base" Data.Semigroup (Semigroup ((<>)))+import "base" Data.String (String)+import "base" Text.Read (Read (readsPrec))+import "base" Text.Show (Show (show))+import "free" Control.Comonad.Cofree (Cofree ((:<)), unwrap)+import "split" Data.List.Split (endBy, splitOn)++-- | What the path points to?+data Points = Directory | File++-- | What is the beginning of the path?+data Origin+	= Root -- ^ (@/@) Starting point for absolute path+	| Home -- ^ (@~/@) Indication of home directory+	| Vague -- ^ Uncertain relative path++-- | Dummy type needed only for beautiful type declarations+data To++-- | Path is non-empty sequence of folders or file (in the end)+type Path = Cofree Maybe String++-- | The internal type of path representation+newtype Outline (origin :: Origin) (points :: Points) = Outline { outline :: Path }++instance Show (Outline Root Directory) where+	show = flip (<>) "/" . foldr (\x acc -> acc <> "/" <> x) "" . outline++instance Show (Outline Root File) where+	show = foldr (\x acc -> acc <> "/" <> x) "" . outline++instance Show (Outline Home Directory) where+	show = (<>) "~/" . foldr (\x acc -> x <> "/" <> acc) "" . outline++instance Show (Outline Home File) where+	show = (<>) "~/" . init . foldr (\x acc -> x <> "/" <> acc) "" . outline++instance Show (Outline Vague Directory) where+	show = foldr (\x acc -> x <> "/" <> acc) "" . outline++instance Show (Outline Vague File) where+	show = init . foldr (\x acc -> x <> "/" <> acc) "" . outline++instance Read (Outline Root Directory) where+	readsPrec _ ('/':[]) = []+	readsPrec _ ('/':rest) = foldr (\el -> Just . (:<) el) Nothing+		(endBy "/" rest) & maybe [] (pure . (,[]) . Outline)+	readsPrec _ _ = []++instance Read (Outline Root File) where+	readsPrec _ ('/':[]) = []+	readsPrec _ ('/':rest) = foldr (\el -> Just . (:<) el) Nothing+		(splitOn "/" rest) & maybe [] (pure . (,[]) . Outline)+	readsPrec _ _ = []++instance Read (Outline Home Directory) where+	readsPrec _ ('~':'/':[]) = []+	readsPrec _ ('~':'/':rest) = foldr (\el -> Just . (:<) el) Nothing+		(endBy "/" rest) & maybe [] (pure . (,[]) . Outline)+	readsPrec _ _ = []++instance Read (Outline Home File) where+	readsPrec _ ('~':'/':[]) = []+	readsPrec _ ('~':'/':rest) = foldr (\el -> Just . (:<) el) Nothing+		(splitOn "/" rest) & maybe [] (pure . (,[]) . Outline)+	readsPrec _ _ = []++instance Read (Outline Vague Directory) where+	readsPrec _ [] = []+	readsPrec _ string = foldr (\el -> Just . (:<) el) Nothing+		(endBy "/" string) & maybe [] (pure . (,[]) . Outline)++instance Read (Outline Vague File) where+	readsPrec _ [] = []+	readsPrec _ string = foldr (\el -> Just . (:<) el) Nothing+		(splitOn "/" string) & maybe [] (pure . (,[]) . Outline)++type family Absolute (path :: Type) (to :: Type) (points :: Points) :: Type where+	Absolute Path To points = Outline Root points++type family Homeward (path :: Type) (to :: Type) (points :: Points) :: Type where+	Homeward Path To points = Outline Home points++type family Relative (path :: Type) (to :: Type) (points :: Points) :: Type where+	Relative Path To points = Outline Vague points++-- | Immerse string into a path, filter slashes+part :: String -> Outline origin points+part x = Outline $ (filter (== '/') x) :< Nothing++{-| @+"usr//local///" + "etc///" = "usr///local///etc//"+@ -}+(<^>) :: Relative Path To Directory -> Relative Path To points -> Relative Path To points+Outline (x :< Nothing) <^> Outline that = Outline $ x :< Just that+Outline (x :< Just this) <^> Outline that = part x <^> (Outline this <^> Outline that)++{-| @+"//usr///bin///" + "git" = "///usr///bin//git"+@ -}+(</>) :: Absolute Path To Directory -> Relative Path To points -> Absolute Path To points+Outline absolute </> Outline (x :< Nothing) = Outline . (:<) x . Just $ absolute+Outline absolute </> Outline (x :< Just xs) = (Outline . (:<) x . Just $ absolute) </> Outline xs++{-| @+"//usr///local///" + "~///etc///" = "///usr///local///etc//"+@ -}+(<~/>) :: Absolute Path To points -> Homeward Path To points -> Absolute Path To points+Outline absolute <~/> Outline (x :< Nothing) = Outline . (:<) x . Just $ absolute+Outline absolute <~/> Outline (x :< Just xs) = (Outline . (:<) x . Just $ absolute) <~/> Outline xs++-- | Take parent directory of current pointed entity+parent :: Absolute Path To points -> Maybe (Absolute Path To Directory)+parent = (<$>) Outline . unwrap . outline++-- | Take the next piece of relative path+deeper :: Relative Path To points -> Maybe (Relative Path To points)+deeper = (<$>) Outline . unwrap . outline
+ System/Monopati/Windows/Calls.hs view
@@ -0,0 +1,1 @@+module System.Monopati.Windows.Calls where
+ System/Monopati/Windows/Combinators.hs view
@@ -0,0 +1,1 @@+module System.Monopati.Windows.Combinators where
monopati.cabal view
@@ -1,5 +1,5 @@ name:                monopati-version:             0.1.1+version:             0.1.2 synopsis:            Well-typed paths description:         Despite the fact that there are a plenty of various well-typed "path" libraries in Haskell, I decided to write new one that I would like to use. homepage:            https://github.com/iokasimov/monopati@@ -17,8 +17,23 @@   location: https://github.com/iokasimov/monopati.git  library-  build-depends: base == 4.*, free, split-  default-extensions: DataKinds, FlexibleInstances, KindSignatures, NoImplicitPrelude, PackageImports, TypeApplications, TypeFamilies+  build-depends: base == 4.*, directory, free, split+  default-extensions:+    DataKinds+    FlexibleInstances+    KindSignatures+    NoImplicitPrelude+    PackageImports+    TupleSections+    TypeApplications+    TypeFamilies   default-language: Haskell2010-  exposed-modules: System.Monopati.Posix, System.Monopati.Windows+  exposed-modules:+    System.Monopati.Posix+    System.Monopati.Windows+  other-modules:+    System.Monopati.Posix.Calls+    System.Monopati.Posix.Combinators+    System.Monopati.Windows.Calls+    System.Monopati.Windows.Combinators   ghc-options: -fno-warn-tabs