2eed840024
travis build: 68
commit: c5bcb90b65
auto-pushed to gh-pages
105 lines
30 KiB
HTML
105 lines
30 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>HPath</title><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean" /><script src="haddock-util.js" type="text/javascript"></script><script type="text/javascript">//<![CDATA[
|
|
window.onload = function () {pageLoad();setSynopsis("mini_HPath.html");};
|
|
//]]>
|
|
</script></head><body><div id="package-header"><ul class="links" id="page-menu"><li><a href="src/HPath.html">Source</a></li><li><a href="index.html">Contents</a></li><li><a href="doc-index.html">Index</a></li></ul><p class="caption">hpath-0.7.5: Support for well-typed paths</p></div><div id="content"><div id="module-header"><table class="info"><tr><th>Copyright</th><td>© 2015–2016 FP Complete, 2016 Julian Ospald</td></tr><tr><th>License</th><td>BSD 3 clause</td></tr><tr><th>Maintainer</th><td>Julian Ospald <hasufell@posteo.de></td></tr><tr><th>Stability</th><td>experimental</td></tr><tr><th>Portability</th><td>portable</td></tr><tr><th>Safe Haskell</th><td>Safe</td></tr><tr><th>Language</th><td>Haskell2010</td></tr></table><p class="caption">HPath</p></div><div id="table-of-contents"><p class="caption">Contents</p><ul><li><a href="#g:1">Types</a></li><li><a href="#g:2">PatternSynonyms/ViewPatterns</a></li><li><a href="#g:3">Path Parsing</a></li><li><a href="#g:4">Path Conversion</a></li><li><a href="#g:5">Path Operations</a></li><li><a href="#g:6">Path IO helpers</a></li></ul></div><div id="description"><p class="caption">Description</p><div class="doc"><p>Support for well-typed paths.</p></div></div><div id="synopsis"><p id="control.syn" class="caption expander" onclick="toggleSection('syn')">Synopsis</p><ul id="section.syn" class="hide" onclick="toggleSection('syn')"><li class="src short"><span class="keyword">data</span> <a href="#t:Abs">Abs</a></li><li class="src short"><span class="keyword">data</span> <a href="#t:Path">Path</a> b</li><li class="src short"><span class="keyword">data</span> <a href="#t:Rel">Rel</a></li><li class="src short"><span class="keyword">data</span> <a href="#t:Fn">Fn</a></li><li class="src short"><span class="keyword">data</span> <a href="#t:PathParseException">PathParseException</a></li><li class="src short"><span class="keyword">data</span> <a href="#t:PathException">PathException</a></li><li class="src short"><span class="keyword">class</span> <a href="#t:RelC">RelC</a> m</li><li class="src short"><span class="keyword">pattern</span> <a href="#v:Path">Path</a> :: <a href="https://hackage.haskell.org/package/bytestring-0.10.6.0/docs/Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="HPath.html#t:Path">Path</a> a</li><li class="src short"><a href="#v:parseAbs">parseAbs</a> :: MonadThrow m => <a href="https://hackage.haskell.org/package/bytestring-0.10.6.0/docs/Data-ByteString.html#t:ByteString">ByteString</a> -> m (<a href="HPath.html#t:Path">Path</a> <a href="HPath.html#t:Abs">Abs</a>)</li><li class="src short"><a href="#v:parseFn">parseFn</a> :: MonadThrow m => <a href="https://hackage.haskell.org/package/bytestring-0.10.6.0/docs/Data-ByteString.html#t:ByteString">ByteString</a> -> m (<a href="HPath.html#t:Path">Path</a> <a href="HPath.html#t:Fn">Fn</a>)</li><li class="src short"><a href="#v:parseRel">parseRel</a> :: MonadThrow m => <a href="https://hackage.haskell.org/package/bytestring-0.10.6.0/docs/Data-ByteString.html#t:ByteString">ByteString</a> -> m (<a href="HPath.html#t:Path">Path</a> <a href="HPath.html#t:Rel">Rel</a>)</li><li class="src short"><a href="#v:fromAbs">fromAbs</a> :: <a href="HPath.html#t:Path">Path</a> <a href="HPath.html#t:Abs">Abs</a> -> <a href="https://hackage.haskell.org/package/bytestring-0.10.6.0/docs/Data-ByteString.html#t:ByteString">ByteString</a></li><li class="src short"><a href="#v:fromRel">fromRel</a> :: <a href="HPath.html#t:RelC">RelC</a> r => <a href="HPath.html#t:Path">Path</a> r -> <a href="https://hackage.haskell.org/package/bytestring-0.10.6.0/docs/Data-ByteString.html#t:ByteString">ByteString</a></li><li class="src short"><a href="#v:toFilePath">toFilePath</a> :: <a href="HPath.html#t:Path">Path</a> b -> <a href="https://hackage.haskell.org/package/bytestring-0.10.6.0/docs/Data-ByteString.html#t:ByteString">ByteString</a></li><li class="src short"><a href="#v:-60--47--62-">(</>)</a> :: <a href="HPath.html#t:RelC">RelC</a> r => <a href="HPath.html#t:Path">Path</a> b -> <a href="HPath.html#t:Path">Path</a> r -> <a href="HPath.html#t:Path">Path</a> b</li><li class="src short"><a href="#v:basename">basename</a> :: MonadThrow m => <a href="HPath.html#t:Path">Path</a> b -> m (<a href="HPath.html#t:Path">Path</a> <a href="HPath.html#t:Fn">Fn</a>)</li><li class="src short"><a href="#v:dirname">dirname</a> :: <a href="HPath.html#t:Path">Path</a> <a href="HPath.html#t:Abs">Abs</a> -> <a href="HPath.html#t:Path">Path</a> <a href="HPath.html#t:Abs">Abs</a></li><li class="src short"><a href="#v:isParentOf">isParentOf</a> :: <a href="HPath.html#t:Path">Path</a> b -> <a href="HPath.html#t:Path">Path</a> b -> <a href="https://hackage.haskell.org/package/base-4.8.1.0/docs/Data-Bool.html#t:Bool">Bool</a></li><li class="src short"><a href="#v:getAllParents">getAllParents</a> :: <a href="HPath.html#t:Path">Path</a> <a href="HPath.html#t:Abs">Abs</a> -> [<a href="HPath.html#t:Path">Path</a> <a href="HPath.html#t:Abs">Abs</a>]</li><li class="src short"><a href="#v:stripDir">stripDir</a> :: MonadThrow m => <a href="HPath.html#t:Path">Path</a> b -> <a href="HPath.html#t:Path">Path</a> b -> m (<a href="HPath.html#t:Path">Path</a> <a href="HPath.html#t:Rel">Rel</a>)</li><li class="src short"><a href="#v:withAbsPath">withAbsPath</a> :: <a href="HPath.html#t:Path">Path</a> <a href="HPath.html#t:Abs">Abs</a> -> (<a href="https://hackage.haskell.org/package/bytestring-0.10.6.0/docs/Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="https://hackage.haskell.org/package/base-4.8.1.0/docs/System-IO.html#t:IO">IO</a> a) -> <a href="https://hackage.haskell.org/package/base-4.8.1.0/docs/System-IO.html#t:IO">IO</a> a</li><li class="src short"><a href="#v:withRelPath">withRelPath</a> :: <a href="HPath.html#t:Path">Path</a> <a href="HPath.html#t:Rel">Rel</a> -> (<a href="https://hackage.haskell.org/package/bytestring-0.10.6.0/docs/Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="https://hackage.haskell.org/package/base-4.8.1.0/docs/System-IO.html#t:IO">IO</a> a) -> <a href="https://hackage.haskell.org/package/base-4.8.1.0/docs/System-IO.html#t:IO">IO</a> a</li><li class="src short"><a href="#v:withFnPath">withFnPath</a> :: <a href="HPath.html#t:Path">Path</a> <a href="HPath.html#t:Fn">Fn</a> -> (<a href="https://hackage.haskell.org/package/bytestring-0.10.6.0/docs/Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="https://hackage.haskell.org/package/base-4.8.1.0/docs/System-IO.html#t:IO">IO</a> a) -> <a href="https://hackage.haskell.org/package/base-4.8.1.0/docs/System-IO.html#t:IO">IO</a> a</li></ul></div><div id="interface"><h1 id="g:1">Types</h1><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:Abs" class="def">Abs</a> <a href="src/HPath.html#Abs" class="link">Source</a></p><div class="doc"><p>An absolute path.</p></div></div><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:Path" class="def">Path</a> b <a href="src/HPath-Internal.html#Path" class="link">Source</a></p><div class="doc"><p>Path of some base and type.</p><p>Internally is a ByteString. The ByteString can be of two formats only:</p><ol><li>without trailing path separator: <code>file.txt</code>, <code>foo/bar.txt</code>, <code>/foo/bar.txt</code></li><li>with trailing path separator: <code>foo/</code>, <code>/foo/bar/</code></li></ol><p>There are no duplicate
|
|
path separators <code>//</code>, no <code>..</code>, no <code>./</code>, no <code>~/</code>, etc.</p></div><div class="subs instances"><p id="control.i:Path" class="caption collapser" onclick="toggleSection('i:Path')">Instances</p><div id="section.i:Path" class="show"><table><tr><td class="src clearfix"><span class="inst-left"><a href="https://hackage.haskell.org/package/base-4.8.1.0/docs/Data-Eq.html#t:Eq">Eq</a> (<a href="HPath.html#t:Path">Path</a> b)</span> <a href="src/HPath-Internal.html#line-30" class="link">Source</a></td><td class="doc"><p>ByteString equality.</p><p>The following property holds:</p><pre>show x == show y ≡ x == y</pre></td></tr><tr><td class="src clearfix"><span class="inst-left"><a href="https://hackage.haskell.org/package/base-4.8.1.0/docs/Data-Ord.html#t:Ord">Ord</a> (<a href="HPath.html#t:Path">Path</a> b)</span> <a href="src/HPath-Internal.html#line-38" class="link">Source</a></td><td class="doc"><p>ByteString ordering.</p><p>The following property holds:</p><pre>show x `compare` show y ≡ x `compare` y</pre></td></tr><tr><td class="src clearfix"><span class="inst-left"><a href="https://hackage.haskell.org/package/base-4.8.1.0/docs/Text-Show.html#t:Show">Show</a> (<a href="HPath.html#t:Path">Path</a> b)</span> <a href="src/HPath-Internal.html#line-46" class="link">Source</a></td><td class="doc"><p>Same as <code><a href="HPath.html#v:toFilePath">toFilePath</a></code>.</p><p>The following property holds:</p><pre>x == y ≡ show x == show y</pre></td></tr><tr><td class="src clearfix"><span class="inst-left"><a href="https://hackage.haskell.org/package/deepseq-1.4.1.1/docs/Control-DeepSeq.html#t:NFData">NFData</a> (<a href="HPath.html#t:Path">Path</a> b)</span> <a href="src/HPath-Internal.html#line-49" class="link">Source</a></td><td class="doc empty"> </td></tr></table></div></div></div><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:Rel" class="def">Rel</a> <a href="src/HPath.html#Rel" class="link">Source</a></p><div class="doc"><p>A relative path; one without a root.</p></div><div class="subs instances"><p id="control.i:Rel" class="caption collapser" onclick="toggleSection('i:Rel')">Instances</p><div id="section.i:Rel" class="show"><table><tr><td class="src clearfix"><span class="inst-left"><a href="HPath.html#t:RelC">RelC</a> <a href="HPath.html#t:Rel">Rel</a></span> <a href="src/HPath.html#line-95" class="link">Source</a></td><td class="doc empty"> </td></tr></table></div></div></div><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:Fn" class="def">Fn</a> <a href="src/HPath.html#Fn" class="link">Source</a></p><div class="doc"><p>A filename, without any <code><a href="https://hackage.haskell.org/package/base-4.8.1.0/docs/Prelude.html#v:-47-">/</a></code>.</p></div><div class="subs instances"><p id="control.i:Fn" class="caption collapser" onclick="toggleSection('i:Fn')">Instances</p><div id="section.i:Fn" class="show"><table><tr><td class="src clearfix"><span class="inst-left"><a href="HPath.html#t:RelC">RelC</a> <a href="HPath.html#t:Fn">Fn</a></span> <a href="src/HPath.html#line-96" class="link">Source</a></td><td class="doc empty"> </td></tr></table></div></div></div><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:PathParseException" class="def">PathParseException</a> <a href="src/HPath.html#PathParseException" class="link">Source</a></p><div class="doc"><p>Exception when parsing a location.</p></div><div class="subs instances"><p id="control.i:PathParseException" class="caption collapser" onclick="toggleSection('i:PathParseException')">Instances</p><div id="section.i:PathParseException" class="show"><table><tr><td class="src clearfix"><span class="inst-left"><a href="https://hackage.haskell.org/package/base-4.8.1.0/docs/Text-Show.html#t:Show">Show</a> <a href="HPath.html#t:PathParseException">PathParseException</a></span> <a href="src/HPath.html#line-86" class="link">Source</a></td><td class="doc empty"> </td></tr><tr><td class="src clearfix"><span class="inst-left"><a href="https://hackage.haskell.org/package/base-4.8.1.0/docs/Control-Exception-Base.html#t:Exception">Exception</a> <a href="HPath.html#t:PathParseException">PathParseException</a></span> <a href="src/HPath.html#line-87" class="link">Source</a></td><td class="doc empty"> </td></tr></table></div></div></div><div class="top"><p class="src"><span class="keyword">data</span> <a name="t:PathException" class="def">PathException</a> <a href="src/HPath.html#PathException" class="link">Source</a></p><div class="subs instances"><p id="control.i:PathException" class="caption collapser" onclick="toggleSection('i:PathException')">Instances</p><div id="section.i:PathException" class="show"><table><tr><td class="src clearfix"><span class="inst-left"><a href="https://hackage.haskell.org/package/base-4.8.1.0/docs/Text-Show.html#t:Show">Show</a> <a href="HPath.html#t:PathException">PathException</a></span> <a href="src/HPath.html#line-90" class="link">Source</a></td><td class="doc empty"> </td></tr><tr><td class="src clearfix"><span class="inst-left"><a href="https://hackage.haskell.org/package/base-4.8.1.0/docs/Control-Exception-Base.html#t:Exception">Exception</a> <a href="HPath.html#t:PathException">PathException</a></span> <a href="src/HPath.html#line-91" class="link">Source</a></td><td class="doc empty"> </td></tr></table></div></div></div><div class="top"><p class="src"><span class="keyword">class</span> <a name="t:RelC" class="def">RelC</a> m <a href="src/HPath.html#RelC" class="link">Source</a></p><div class="subs instances"><p id="control.i:RelC" class="caption collapser" onclick="toggleSection('i:RelC')">Instances</p><div id="section.i:RelC" class="show"><table><tr><td class="src clearfix"><span class="inst-left"><a href="HPath.html#t:RelC">RelC</a> <a href="HPath.html#t:Fn">Fn</a></span> <a href="src/HPath.html#line-96" class="link">Source</a></td><td class="doc empty"> </td></tr><tr><td class="src clearfix"><span class="inst-left"><a href="HPath.html#t:RelC">RelC</a> <a href="HPath.html#t:Rel">Rel</a></span> <a href="src/HPath.html#line-95" class="link">Source</a></td><td class="doc empty"> </td></tr></table></div></div></div><h1 id="g:2">PatternSynonyms/ViewPatterns</h1><div class="top"><p class="src"><span class="keyword">pattern</span> <a name="v:Path" class="def">Path</a> :: <a href="https://hackage.haskell.org/package/bytestring-0.10.6.0/docs/Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="HPath.html#t:Path">Path</a> a <a href="src/HPath.html#Path" class="link">Source</a></p></div><h1 id="g:3">Path Parsing</h1><div class="top"><p class="src"><a name="v:parseAbs" class="def">parseAbs</a> :: MonadThrow m => <a href="https://hackage.haskell.org/package/bytestring-0.10.6.0/docs/Data-ByteString.html#t:ByteString">ByteString</a> -> m (<a href="HPath.html#t:Path">Path</a> <a href="HPath.html#t:Abs">Abs</a>) <a href="src/HPath.html#parseAbs" class="link">Source</a></p><div class="doc"><p>Get a location for an absolute path. Produces a normalised path.</p><p>Throws: <code><a href="HPath.html#t:PathParseException">PathParseException</a></code></p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>parseAbs "/abc" :: Maybe (Path Abs)
|
|
</code></strong>Just "/abc"
|
|
<code class="prompt">>>> </code><strong class="userinput"><code>parseAbs "/" :: Maybe (Path Abs)
|
|
</code></strong>Just "/"
|
|
<code class="prompt">>>> </code><strong class="userinput"><code>parseAbs "/abc/def" :: Maybe (Path Abs)
|
|
</code></strong>Just "/abc/def"
|
|
<code class="prompt">>>> </code><strong class="userinput"><code>parseAbs "/abc/def/.///" :: Maybe (Path Abs)
|
|
</code></strong>Just "/abc/def/"
|
|
<code class="prompt">>>> </code><strong class="userinput"><code>parseAbs "abc" :: Maybe (Path Abs)
|
|
</code></strong>Nothing
|
|
<code class="prompt">>>> </code><strong class="userinput"><code>parseAbs "" :: Maybe (Path Abs)
|
|
</code></strong>Nothing
|
|
<code class="prompt">>>> </code><strong class="userinput"><code>parseAbs "/abc/../foo" :: Maybe (Path Abs)
|
|
</code></strong>Nothing
|
|
</pre></div></div><div class="top"><p class="src"><a name="v:parseFn" class="def">parseFn</a> :: MonadThrow m => <a href="https://hackage.haskell.org/package/bytestring-0.10.6.0/docs/Data-ByteString.html#t:ByteString">ByteString</a> -> m (<a href="HPath.html#t:Path">Path</a> <a href="HPath.html#t:Fn">Fn</a>) <a href="src/HPath.html#parseFn" class="link">Source</a></p><div class="doc"><p>Parses a filename. Filenames must not contain slashes.
|
|
Excludes <code><a href="https://hackage.haskell.org/package/base-4.8.1.0/docs/Data-Function.html#v:.">.</a></code> and '..'.</p><p>Throws: <code><a href="HPath.html#t:PathParseException">PathParseException</a></code></p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>parseFn "abc" :: Maybe (Path Fn)
|
|
</code></strong>Just "abc"
|
|
<code class="prompt">>>> </code><strong class="userinput"><code>parseFn "..." :: Maybe (Path Fn)
|
|
</code></strong>Just "..."
|
|
<code class="prompt">>>> </code><strong class="userinput"><code>parseFn "def/" :: Maybe (Path Fn)
|
|
</code></strong>Nothing
|
|
<code class="prompt">>>> </code><strong class="userinput"><code>parseFn "abc/def" :: Maybe (Path Fn)
|
|
</code></strong>Nothing
|
|
<code class="prompt">>>> </code><strong class="userinput"><code>parseFn "abc/def/." :: Maybe (Path Fn)
|
|
</code></strong>Nothing
|
|
<code class="prompt">>>> </code><strong class="userinput"><code>parseFn "/abc" :: Maybe (Path Fn)
|
|
</code></strong>Nothing
|
|
<code class="prompt">>>> </code><strong class="userinput"><code>parseFn "" :: Maybe (Path Fn)
|
|
</code></strong>Nothing
|
|
<code class="prompt">>>> </code><strong class="userinput"><code>parseFn "abc/../foo" :: Maybe (Path Fn)
|
|
</code></strong>Nothing
|
|
<code class="prompt">>>> </code><strong class="userinput"><code>parseFn "." :: Maybe (Path Fn)
|
|
</code></strong>Nothing
|
|
<code class="prompt">>>> </code><strong class="userinput"><code>parseFn ".." :: Maybe (Path Fn)
|
|
</code></strong>Nothing
|
|
</pre></div></div><div class="top"><p class="src"><a name="v:parseRel" class="def">parseRel</a> :: MonadThrow m => <a href="https://hackage.haskell.org/package/bytestring-0.10.6.0/docs/Data-ByteString.html#t:ByteString">ByteString</a> -> m (<a href="HPath.html#t:Path">Path</a> <a href="HPath.html#t:Rel">Rel</a>) <a href="src/HPath.html#parseRel" class="link">Source</a></p><div class="doc"><p>Get a location for a relative path. Produces a normalised
|
|
path.</p><p>Note that <code>filepath</code> may contain any number of <code>./</code> but may not consist
|
|
solely of <code>./</code>. It also may not contain a single <code>..</code> anywhere.</p><p>Throws: <code><a href="HPath.html#t:PathParseException">PathParseException</a></code></p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>parseRel "abc" :: Maybe (Path Rel)
|
|
</code></strong>Just "abc"
|
|
<code class="prompt">>>> </code><strong class="userinput"><code>parseRel "def/" :: Maybe (Path Rel)
|
|
</code></strong>Just "def/"
|
|
<code class="prompt">>>> </code><strong class="userinput"><code>parseRel "abc/def" :: Maybe (Path Rel)
|
|
</code></strong>Just "abc/def"
|
|
<code class="prompt">>>> </code><strong class="userinput"><code>parseRel "abc/def/." :: Maybe (Path Rel)
|
|
</code></strong>Just "abc/def/"
|
|
<code class="prompt">>>> </code><strong class="userinput"><code>parseRel "/abc" :: Maybe (Path Rel)
|
|
</code></strong>Nothing
|
|
<code class="prompt">>>> </code><strong class="userinput"><code>parseRel "" :: Maybe (Path Rel)
|
|
</code></strong>Nothing
|
|
<code class="prompt">>>> </code><strong class="userinput"><code>parseRel "abc/../foo" :: Maybe (Path Rel)
|
|
</code></strong>Nothing
|
|
<code class="prompt">>>> </code><strong class="userinput"><code>parseRel "." :: Maybe (Path Rel)
|
|
</code></strong>Nothing
|
|
<code class="prompt">>>> </code><strong class="userinput"><code>parseRel ".." :: Maybe (Path Rel)
|
|
</code></strong>Nothing
|
|
</pre></div></div><h1 id="g:4">Path Conversion</h1><div class="top"><p class="src"><a name="v:fromAbs" class="def">fromAbs</a> :: <a href="HPath.html#t:Path">Path</a> <a href="HPath.html#t:Abs">Abs</a> -> <a href="https://hackage.haskell.org/package/bytestring-0.10.6.0/docs/Data-ByteString.html#t:ByteString">ByteString</a> <a href="src/HPath.html#fromAbs" class="link">Source</a></p><div class="doc"><p>Convert an absolute Path to a ByteString type.</p></div></div><div class="top"><p class="src"><a name="v:fromRel" class="def">fromRel</a> :: <a href="HPath.html#t:RelC">RelC</a> r => <a href="HPath.html#t:Path">Path</a> r -> <a href="https://hackage.haskell.org/package/bytestring-0.10.6.0/docs/Data-ByteString.html#t:ByteString">ByteString</a> <a href="src/HPath.html#fromRel" class="link">Source</a></p><div class="doc"><p>Convert a relative Path to a ByteString type.</p></div></div><div class="top"><p class="src"><a name="v:toFilePath" class="def">toFilePath</a> :: <a href="HPath.html#t:Path">Path</a> b -> <a href="https://hackage.haskell.org/package/bytestring-0.10.6.0/docs/Data-ByteString.html#t:ByteString">ByteString</a> <a href="src/HPath.html#toFilePath" class="link">Source</a></p><div class="doc"><p>Convert any Path to a ByteString type.</p></div></div><h1 id="g:5">Path Operations</h1><div class="top"><p class="src"><a name="v:-60--47--62-" class="def">(</>)</a> :: <a href="HPath.html#t:RelC">RelC</a> r => <a href="HPath.html#t:Path">Path</a> b -> <a href="HPath.html#t:Path">Path</a> r -> <a href="HPath.html#t:Path">Path</a> b <a href="src/HPath.html#%3C%2F%3E" class="link">Source</a></p><div class="doc"><p>Append two paths.</p><p>The second argument must always be a relative path, which ensures
|
|
that undefinable things like `"<em>abc" <</em>> "/def"` cannot happen.</p><p>Technically, the first argument can be a path that points to a non-directory,
|
|
because this library is IO-agnostic and makes no assumptions about
|
|
file types.</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>(MkPath "/") </> (MkPath "file" :: Path Rel)
|
|
</code></strong>"/file"
|
|
<code class="prompt">>>> </code><strong class="userinput"><code>(MkPath "/path/to") </> (MkPath "file" :: Path Rel)
|
|
</code></strong>"/path/to/file"
|
|
<code class="prompt">>>> </code><strong class="userinput"><code>(MkPath "/") </> (MkPath "file/lal" :: Path Rel)
|
|
</code></strong>"/file/lal"
|
|
<code class="prompt">>>> </code><strong class="userinput"><code>(MkPath "/") </> (MkPath "file/" :: Path Rel)
|
|
</code></strong>"/file/"
|
|
</pre></div></div><div class="top"><p class="src"><a name="v:basename" class="def">basename</a> :: MonadThrow m => <a href="HPath.html#t:Path">Path</a> b -> m (<a href="HPath.html#t:Path">Path</a> <a href="HPath.html#t:Fn">Fn</a>) <a href="src/HPath.html#basename" class="link">Source</a></p><div class="doc"><p>Extract the file part of a path.</p><p>The following properties hold:</p><pre>basename (p </> a) == basename a</pre><p>Throws: <code><a href="HPath.html#t:PathException">PathException</a></code> if given the root path "/"</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>basename (MkPath "/abc/def/dod") :: Maybe (Path Fn)
|
|
</code></strong>Just "dod"
|
|
<code class="prompt">>>> </code><strong class="userinput"><code>basename (MkPath "/") :: Maybe (Path Fn)
|
|
</code></strong>Nothing
|
|
</pre></div></div><div class="top"><p class="src"><a name="v:dirname" class="def">dirname</a> :: <a href="HPath.html#t:Path">Path</a> <a href="HPath.html#t:Abs">Abs</a> -> <a href="HPath.html#t:Path">Path</a> <a href="HPath.html#t:Abs">Abs</a> <a href="src/HPath.html#dirname" class="link">Source</a></p><div class="doc"><p>Extract the directory name of a path.</p><p>The following properties hold:</p><pre>dirname (p </> a) == dirname p</pre><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>dirname (MkPath "/abc/def/dod")
|
|
</code></strong>"/abc/def"
|
|
<code class="prompt">>>> </code><strong class="userinput"><code>dirname (MkPath "/")
|
|
</code></strong>"/"
|
|
</pre></div></div><div class="top"><p class="src"><a name="v:isParentOf" class="def">isParentOf</a> :: <a href="HPath.html#t:Path">Path</a> b -> <a href="HPath.html#t:Path">Path</a> b -> <a href="https://hackage.haskell.org/package/base-4.8.1.0/docs/Data-Bool.html#t:Bool">Bool</a> <a href="src/HPath.html#isParentOf" class="link">Source</a></p><div class="doc"><p>Is p a parent of the given location? Implemented in terms of
|
|
<code><a href="HPath.html#v:stripDir">stripDir</a></code>. The bases must match.</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>(MkPath "/lal/lad") `isParentOf` (MkPath "/lal/lad/fad")
|
|
</code></strong>True
|
|
<code class="prompt">>>> </code><strong class="userinput"><code>(MkPath "lal/lad") `isParentOf` (MkPath "lal/lad/fad")
|
|
</code></strong>True
|
|
<code class="prompt">>>> </code><strong class="userinput"><code>(MkPath "/") `isParentOf` (MkPath "/")
|
|
</code></strong>False
|
|
<code class="prompt">>>> </code><strong class="userinput"><code>(MkPath "/lal/lad/fad") `isParentOf` (MkPath "/lal/lad")
|
|
</code></strong>False
|
|
<code class="prompt">>>> </code><strong class="userinput"><code>(MkPath "fad") `isParentOf` (MkPath "fad")
|
|
</code></strong>False
|
|
</pre></div></div><div class="top"><p class="src"><a name="v:getAllParents" class="def">getAllParents</a> :: <a href="HPath.html#t:Path">Path</a> <a href="HPath.html#t:Abs">Abs</a> -> [<a href="HPath.html#t:Path">Path</a> <a href="HPath.html#t:Abs">Abs</a>] <a href="src/HPath.html#getAllParents" class="link">Source</a></p><div class="doc"><p>Get all parents of a path.</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>getAllParents (MkPath "/abs/def/dod")
|
|
</code></strong>["/abs/def","/abs","/"]
|
|
<code class="prompt">>>> </code><strong class="userinput"><code>getAllParents (MkPath "/")
|
|
</code></strong>[]
|
|
</pre></div></div><div class="top"><p class="src"><a name="v:stripDir" class="def">stripDir</a> :: MonadThrow m => <a href="HPath.html#t:Path">Path</a> b -> <a href="HPath.html#t:Path">Path</a> b -> m (<a href="HPath.html#t:Path">Path</a> <a href="HPath.html#t:Rel">Rel</a>) <a href="src/HPath.html#stripDir" class="link">Source</a></p><div class="doc"><p>Strip directory from path, making it relative to that directory.
|
|
Throws <code>Couldn'tStripPrefixDir</code> if directory is not a parent of the path.</p><p>The bases must match.</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>(MkPath "/lal/lad") `stripDir` (MkPath "/lal/lad/fad") :: Maybe (Path Rel)
|
|
</code></strong>Just "fad"
|
|
<code class="prompt">>>> </code><strong class="userinput"><code>(MkPath "lal/lad") `stripDir` (MkPath "lal/lad/fad") :: Maybe (Path Rel)
|
|
</code></strong>Just "fad"
|
|
<code class="prompt">>>> </code><strong class="userinput"><code>(MkPath "/") `stripDir` (MkPath "/") :: Maybe (Path Rel)
|
|
</code></strong>Nothing
|
|
<code class="prompt">>>> </code><strong class="userinput"><code>(MkPath "/lal/lad/fad") `stripDir` (MkPath "/lal/lad") :: Maybe (Path Rel)
|
|
</code></strong>Nothing
|
|
<code class="prompt">>>> </code><strong class="userinput"><code>(MkPath "fad") `stripDir` (MkPath "fad") :: Maybe (Path Rel)
|
|
</code></strong>Nothing
|
|
</pre></div></div><h1 id="g:6">Path IO helpers</h1><div class="top"><p class="src"><a name="v:withAbsPath" class="def">withAbsPath</a> :: <a href="HPath.html#t:Path">Path</a> <a href="HPath.html#t:Abs">Abs</a> -> (<a href="https://hackage.haskell.org/package/bytestring-0.10.6.0/docs/Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="https://hackage.haskell.org/package/base-4.8.1.0/docs/System-IO.html#t:IO">IO</a> a) -> <a href="https://hackage.haskell.org/package/base-4.8.1.0/docs/System-IO.html#t:IO">IO</a> a <a href="src/HPath.html#withAbsPath" class="link">Source</a></p></div><div class="top"><p class="src"><a name="v:withRelPath" class="def">withRelPath</a> :: <a href="HPath.html#t:Path">Path</a> <a href="HPath.html#t:Rel">Rel</a> -> (<a href="https://hackage.haskell.org/package/bytestring-0.10.6.0/docs/Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="https://hackage.haskell.org/package/base-4.8.1.0/docs/System-IO.html#t:IO">IO</a> a) -> <a href="https://hackage.haskell.org/package/base-4.8.1.0/docs/System-IO.html#t:IO">IO</a> a <a href="src/HPath.html#withRelPath" class="link">Source</a></p></div><div class="top"><p class="src"><a name="v:withFnPath" class="def">withFnPath</a> :: <a href="HPath.html#t:Path">Path</a> <a href="HPath.html#t:Fn">Fn</a> -> (<a href="https://hackage.haskell.org/package/bytestring-0.10.6.0/docs/Data-ByteString.html#t:ByteString">ByteString</a> -> <a href="https://hackage.haskell.org/package/base-4.8.1.0/docs/System-IO.html#t:IO">IO</a> a) -> <a href="https://hackage.haskell.org/package/base-4.8.1.0/docs/System-IO.html#t:IO">IO</a> a <a href="src/HPath.html#withFnPath" class="link">Source</a></p></div></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.16.1</p></div></body></html> |