packages feed

monopati 0.1.0 → 0.1.1

raw patch · 3 files changed

+57/−80 lines, 3 filesdep −comonaddep −directoryPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependencies removed: comonad, directory

API changes (from Hackage documentation)

- System.Monopati: (</>) :: Path Absolute Directory -> Path Relative points -> Path Absolute points
- System.Monopati: (<^>) :: Path Relative Directory -> Path Relative points -> Path Relative points
- System.Monopati: Absolute :: Reference
- System.Monopati: Directory :: Points
- System.Monopati: File :: Points
- System.Monopati: Path :: Stack String -> Path
- System.Monopati: Relative :: Reference
- System.Monopati: [path] :: Path -> Stack String
- System.Monopati: data Path (reference :: Reference) (points :: Points)
- System.Monopati: data Points
- System.Monopati: data Reference
- System.Monopati: instance GHC.Show.Show (System.Monopati.Path 'System.Monopati.Absolute points)
- System.Monopati: instance GHC.Show.Show (System.Monopati.Path 'System.Monopati.Relative points)
- System.Monopati: next :: Path Relative points -> String
- System.Monopati: part :: String -> Path referece points
- System.Monopati: points :: Path Absolute points -> String
- System.Monopati.Posix: change :: Path Absolute Directory -> IO (Path Absolute Directory)
- System.Monopati.Posix: create :: Path Relative Directory -> IO (Path Absolute Directory)
- System.Monopati.Posix: current :: IO (Maybe (Path Absolute Directory))
+ System.Monopati.Posix: (</>) :: Absolute Path To Directory -> Relative Path To points -> Absolute Path To points
+ System.Monopati.Posix: (<^>) :: Relative Path To Directory -> Relative Path To points -> Relative Path To points
+ System.Monopati.Posix: (<~/>) :: Absolute Path To points -> Homeward Path To points -> Absolute Path To points
+ System.Monopati.Posix: Directory :: Points
+ System.Monopati.Posix: File :: Points
+ System.Monopati.Posix: Home :: Origin
+ System.Monopati.Posix: Outline :: Path -> Outline
+ System.Monopati.Posix: Root :: Origin
+ System.Monopati.Posix: Vague :: Origin
+ System.Monopati.Posix: [outline] :: Outline -> Path
+ System.Monopati.Posix: data Origin
+ System.Monopati.Posix: data Points
+ System.Monopati.Posix: data To
+ 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: newtype Outline (origin :: Origin) (points :: Points)
+ System.Monopati.Posix: part :: String -> Outline origin points
+ System.Monopati.Posix: type Path = Cofree Maybe String

Files

− System/Monopati.hs
@@ -1,49 +0,0 @@-module System.Monopati (Path (..), Points (..), Reference (..)-	, part, points, next, (<^>), (</>)) where--import "base" Data.Function ((.), ($))-import "base" Data.Maybe (Maybe (Just, Nothing))-import "base" Data.String (String)-import "base" Data.Semigroup ((<>))-import "base" Text.Show (Show (show))-import "comonad" Control.Comonad (extract)-import "free" Control.Comonad.Cofree (Cofree ((:<)))--type Stack = Cofree Maybe---- | Relative paths defined in direct order, absolute - in reverse-data Reference = Absolute | Relative---- | Path may points to a directory or a file-data Points = Directory | File---- | These two phantom paramaters needs for static analysis-data Path (reference :: Reference) (points :: Points) = Path { path :: Stack String }--instance Show (Path Absolute points) where-	show (Path (x :< Just xs)) = show (Path @Absolute xs) <> "/" <> x-	show (Path (x :< Nothing)) = "/" <> x--instance Show (Path Relative points) where-	show (Path (x :< Just xs)) = x <> "/" <> show (Path @Relative xs)-	show (Path (x :< Nothing)) = x---- | Immerse some string into a path component-part :: String -> Path referece points-part x = Path $ x :< Nothing--points :: Path Absolute points -> String-points = extract . path--next :: Path Relative points -> String-next = extract . path---- | Concatenate Relative and Relative paths-(<^>) :: Path Relative Directory -> Path Relative points -> Path Relative points-Path (x :< Nothing) <^> Path that = Path $ x :< Just that-Path (x :< Just this) <^> Path that = part x <^> (Path this <^> Path that)---- | Concatenate Absolute and Relative paths-(</>) :: Path Absolute Directory -> Path Relative points -> Path Absolute points-Path absolute </> Path (x :< Nothing) = Path . (:<) x . Just $ absolute-Path absolute </> Path (x :< Just xs) = (Path . (:<) x . Just $ absolute) </> Path xs
System/Monopati/Posix.hs view
@@ -1,37 +1,63 @@ module System.Monopati.Posix where -import "base" Control.Applicative ((*>))-import "base" Data.Bool (Bool (True))-import "base" Data.Foldable (foldr)+import "base" Data.Eq (Eq ((==)))+import "base" Data.Foldable (Foldable (foldr)) import "base" Data.Function ((.), ($), flip)-import "base" Data.Functor ((<$>), ($>))-import "base" Data.List (reverse, tail)-import "base" Data.Maybe (Maybe (Just, Nothing), maybe)+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" System.IO (IO)-import "base" Text.Show (show)-import "directory" System.Directory-	(createDirectoryIfMissing, getCurrentDirectory, setCurrentDirectory)+import "base" Text.Show (Show (show)) import "free" Control.Comonad.Cofree (Cofree ((:<)))-import "split" Data.List.Split (splitOn) -import System.Monopati (Path (Path, path), Reference (Absolute, Relative), Points (Directory), (</>))+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 --- | Return Nothing, if current working directory is root (cwd)-current :: IO (Maybe (Path Absolute Directory))-current = parse <$> getCurrentDirectory where+type Path = Cofree Maybe String -	parse :: String -> Maybe (Path Absolute Directory)-	parse "/" = Nothing-	parse directory = (<$>) Path-		. foldr (\el -> Just . (:<) el) Nothing-		. reverse . splitOn "/" . tail $ directory+-- | The internal type of path representation+newtype Outline (origin :: Origin) (points :: Points) = Outline { outline :: Path } --- | Change current working directory (cd)-change :: Path Absolute Directory -> IO (Path Absolute Directory)-change directory = setCurrentDirectory (show directory) $> directory+instance Show (Outline Root Directory) where+	show = flip (<>) "/" . foldr (\x acc -> acc <> "/" <> x) "" . outline --- | Create an absolute path that points to directory (mkdir)-create :: Path Relative Directory -> IO (Path Absolute Directory)-create directory = createDirectoryIfMissing True (show directory) *>-	(maybe (Path @Absolute . path $ directory) (flip (</>) directory) <$> current)+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++(<~/>) :: 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
monopati.cabal view
@@ -1,5 +1,5 @@ name:                monopati-version:             0.1.0+version:             0.1.1 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,8 @@   location: https://github.com/iokasimov/monopati.git  library-  build-depends: base == 4.*, directory, comonad, free, split-  default-extensions: DataKinds, FlexibleInstances, KindSignatures, NoImplicitPrelude, PackageImports, TypeApplications+  build-depends: base == 4.*, free, split+  default-extensions: DataKinds, FlexibleInstances, KindSignatures, NoImplicitPrelude, PackageImports, TypeApplications, TypeFamilies   default-language: Haskell2010-  exposed-modules: System.Monopati, System.Monopati.Posix, System.Monopati.Windows+  exposed-modules: System.Monopati.Posix, System.Monopati.Windows   ghc-options: -fno-warn-tabs