packages feed

monopati (empty) → 0.1.0

raw patch · 6 files changed

+142/−0 lines, 6 filesdep +basedep +comonaddep +directorysetup-changed

Dependencies added: base, comonad, directory, free, split

Files

+ LICENSE view
@@ -0,0 +1,29 @@+BSD 3-Clause License++Copyright (c) 2018, Murat Kasimov+All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++* Redistributions of source code must retain the above copyright notice, this+  list of conditions and the following disclaimer.++* Redistributions in binary form must reproduce the above copyright notice,+  this list of conditions and the following disclaimer in the documentation+  and/or other materials provided with the distribution.++* Neither the name of the copyright holder nor the names of its+  contributors may be used to endorse or promote products derived from+  this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ System/Monopati.hs view
@@ -0,0 +1,49 @@+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
@@ -0,0 +1,37 @@+module System.Monopati.Posix where++import "base" Control.Applicative ((*>))+import "base" Data.Bool (Bool (True))+import "base" Data.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.String (String)+import "base" System.IO (IO)+import "base" Text.Show (show)+import "directory" System.Directory+	(createDirectoryIfMissing, getCurrentDirectory, setCurrentDirectory)+import "free" Control.Comonad.Cofree (Cofree ((:<)))+import "split" Data.List.Split (splitOn)++import System.Monopati (Path (Path, path), Reference (Absolute, Relative), Points (Directory), (</>))++-- | Return Nothing, if current working directory is root (cwd)+current :: IO (Maybe (Path Absolute Directory))+current = parse <$> getCurrentDirectory where++	parse :: String -> Maybe (Path Absolute Directory)+	parse "/" = Nothing+	parse directory = (<$>) Path+		. foldr (\el -> Just . (:<) el) Nothing+		. reverse . splitOn "/" . tail $ directory++-- | Change current working directory (cd)+change :: Path Absolute Directory -> IO (Path Absolute Directory)+change directory = setCurrentDirectory (show directory) $> directory++-- | 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)
+ System/Monopati/Windows.hs view
@@ -0,0 +1,1 @@+module System.Monopati.Windows where
+ monopati.cabal view
@@ -0,0 +1,24 @@+name:                monopati+version:             0.1.0+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+license:             BSD3+license-file:        LICENSE+author:              Murat Kasimov+maintainer:          Murat Kasimov <iokasimov.m@gmail.com>+copyright:           Copyright (c) 2018 Murat Kasimov+category:            System+build-type:          Simple+cabal-version:       >= 1.10++source-repository head+  type: git+  location: https://github.com/iokasimov/monopati.git++library+  build-depends: base == 4.*, directory, comonad, free, split+  default-extensions: DataKinds, FlexibleInstances, KindSignatures, NoImplicitPrelude, PackageImports, TypeApplications+  default-language: Haskell2010+  exposed-modules: System.Monopati, System.Monopati.Posix, System.Monopati.Windows+  ghc-options: -fno-warn-tabs