path-like (empty) → 0.1.0.0
raw patch · 5 files changed
+120/−0 lines, 5 filesdep +basedep +path
Dependencies added: base, path
Files
- ChangeLog.md +6/−0
- LICENSE +21/−0
- README.md +17/−0
- path-like.cabal +37/−0
- src/Path/Like.hs +39/−0
+ ChangeLog.md view
@@ -0,0 +1,6 @@+# Changelog for path-like++## (v0.1.0.0)++* Add `FileLike` and `DirLike` type class for using stricter types as `Path b File` and `Path b Dir` respectively.+* Add `(/>)` combinator for producing a `Path` from a `DirLike` and a `FileLike Rel`.
+ LICENSE view
@@ -0,0 +1,21 @@+MIT License++Copyright (c) 2020 Daniel Firth++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in all+copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE+SOFTWARE.
+ README.md view
@@ -0,0 +1,17 @@+# path-like - Type classes for the Path library.++This library exports two type classes `FileLike` and `DirLike` which serve as a+common interface for compiling types down to `Path b File` and `Path b Dir`.+The only contract that should be respected is that your type should be at least+as strict as the `Path` type itself, i.e no String/FilePath instances. This is+the case with the [within](https://hackage.haskell.org/hackage/within) type.++This library also exports a concatenation function `(/>)` which defers to the+underlying `(</>)` function in `Path`, but works for any `DirLike` and+`PathLike Rel`. This may change to shadow the existing definition if these+classes turn out to be generally useful. They tend to be particularly useful for+generalising file IO, but you may find you need to cast more when you first+construct a `Path` using TemplateHaskell.++For more information see the [path](https://hackage.haskell.org/hackage/path)+library documentation.
+ path-like.cabal view
@@ -0,0 +1,37 @@+cabal-version: 1.12++-- This file has been generated from package.yaml by hpack version 0.34.2.+--+-- see: https://github.com/sol/hpack++name: path-like+version: 0.1.0.0+synopsis: FileLike and DirLike type classes for the Path library.+description: Type classes for the Path library. Exports FileLike and DirLike classes so that stricter types may be used as Paths.+category: Filesystem+author: Daniel Firth+maintainer: dan.firth@homotopic.tech+copyright: 2020 Daniel Firth+license: MIT+license-file: LICENSE+build-type: Simple+extra-source-files:+ README.md+ ChangeLog.md++source-repository head+ type: git+ location: https://gitlab.com/homotopic-tech/path-like++library+ exposed-modules:+ Path.Like+ other-modules:+ Paths_path_like+ hs-source-dirs:+ src+ ghc-options: -Wall -Wcompat -Wincomplete-record-updates -Wincomplete-uni-patterns -Wredundant-constraints+ build-depends:+ base >=4.7 && <5+ , path+ default-language: Haskell2010
+ src/Path/Like.hs view
@@ -0,0 +1,39 @@+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE FunctionalDependencies #-}+{-# LANGUAGE MultiParamTypeClasses #-}+{- |+ Module : Path.Like+ Copyright : Copyright (C) 2020 Daniel Firth+ Maintainer : Daniel Firth <dan.firth@homotopic.tech>+ License : MIT+ Stability : experimental++Type classes for compiling down to well-typed `Path`s.+-}++module Path.Like (+ FileLike(..)+, DirLike(..)+, (/>)+) where++import Path++-- | Class representing a type `a` that can be compiled down to a `Path b File`.+class FileLike b a | a -> b where+ toFile :: a -> Path b File++-- | Class representing a type `a` that can be compiled down to a `Path b Dir`.+class DirLike b a | a -> b where+ toDir :: a -> Path b Dir++instance FileLike b (Path b File) where+ toFile = id++instance DirLike b (Path b Dir) where+ toDir = id++-- | Like `Path.</>`, but works for any `DirLike` and relative `FileLike` to produce a concrete `Path`.+(/>) :: (DirLike b a, FileLike Rel c) => a -> c -> Path b File+(/>) x y = (toDir x) </> (toFile y)