<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><head><metahttp-equiv="Content-Type"content="text/html; charset=UTF-8"/><title>HPath</title><linkhref="ocean.css"rel="stylesheet"type="text/css"title="Ocean"/><scriptsrc="haddock-util.js"type="text/javascript"></script><scripttype="text/javascript">//<![CDATA[
</script></head><body><divid="package-header"><ulclass="links"id="page-menu"><li><ahref="src/HPath.html">Source</a></li><li><ahref="index.html">Contents</a></li><li><ahref="doc-index.html">Index</a></li></ul><pclass="caption">hpath-0.8.0: Support for well-typed paths</p></div><divid="content"><divid="module-header"><tableclass="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-Inferred</td></tr><tr><th>Language</th><td>Haskell2010</td></tr></table><pclass="caption">HPath</p></div><divid="table-of-contents"><pclass="caption">Contents</p><ul><li><ahref="#g:1">Types</a></li><li><ahref="#g:2">PatternSynonyms/ViewPatterns</a></li><li><ahref="#g:3">Path Parsing</a></li><li><ahref="#g:4">Path Conversion</a></li><li><ahref="#g:5">Path Operations</a></li><li><ahref="#g:6">Path IO helpers</a></li></ul></div><divid="description"><pclass="caption">Description</p><divclass="doc"><p>Support for well-typed paths.</p></div></div><divid="synopsis"><pid="control.syn"class="caption expander"onclick="toggleSection('syn')">Synopsis</p><ulid="section.syn"class="hide"onclick="toggleSection('syn')"><liclass="src short"><spanclass="keyword">data</span><ahref="#t:Abs">Abs</a></li><liclass="src short"><spanclass="keyword">data</span><ahref="#t:Path">Path</a> b</li><liclass="src short"><spanclass="keyword">data</span><ahref="#t:Rel">Rel</a></li><liclass="src short"><spanclass="keyword">data</span><ahref="#t:Fn">Fn</a></li><liclass="src short"><spanclass="keyword">data</span><ahref="#t:PathParseException">PathParseException</a></li><liclass="src short"><spanclass="keyword">data</span><ahref="#t:PathException">PathException</a></li><liclass="src short"><spanclass="keyword">class</span><ahref="#t:RelC">RelC</a> m</li><liclass="src short">pattern <ahref="#v:Path">Path</a><ahref="https://hackage.haskell.org/package/bytestring-0.10.4.0/docs/Data-ByteString.html#t:ByteString">ByteString</a> :: <ahref="HPath.html#t:Path">Path</a> t</li><liclass="src short"><ahref="#v:parseAbs">parseAbs</a> :: MonadThrow m =><ahref="https://hackage.haskell.org/package/bytestring-0.10.4.0/docs/Data-ByteString.html#t:ByteString">ByteString</a> -> m (<ahref="HPath.html#t:Path">Path</a><ahref="HPath.html#t:Abs">Abs</a>)</li><liclass="src short"><ahref="#v:parseFn">parseFn</a> :: MonadThrow m =><ahref="https://hackage.haskell.org/package/bytestring-0.10.4.0/docs/Data-ByteString.html#t:ByteString">ByteString</a> -> m (<ahref="HPath.html#t:Path">Path</a><ahref="HPath.html#t:Fn">Fn</a>)</li><liclass="src short"><ahref="#v:parseRel">parseRel</a> :: MonadThrow m =><ahref="https://hackage.haskell.org/package/bytestring-0.10.4.0/docs/Data-ByteString.html#t:ByteString">ByteString</a> -> m (<ahref="HPath.html#t:Path">Path</a><ahref="HPath.html#t:Rel">Rel</a>)</li><liclass="src short"><ahref="#v:fromAbs">fromAbs</a> :: <ahref="HPath.html#t:Path">Path</a><ahref="HPath.html#t:Abs">Abs</a> -><ahref="https://hackage.haskell.org/package/bytestring-0.10.4.0/docs/Data-ByteString.html#t:ByteString">ByteString</a></li><liclass="src short"><ahref="#v:fromRel">fromRel</a> :: <ahref="HPath.html#t:RelC">RelC</a> r =><ahref="HPath.html#t:Path">Path</a> r -><ahref="https://hackage.haskell.org/package/bytestring-0.10.4.0/docs/Data-ByteString.html#t:ByteString">ByteString</a></li><liclass="src short"><ahref="#v:toFilePath">toFilePath</a> :: <ahref="HPath.html#t:Path">Path</a> b -><ahref="https://hackage.haskell.org/package/bytestring-0.10.4.0/docs/Data-ByteString.html#t:ByteString">ByteString</a></li><liclass="src short"><ahref="#v:-60--47--62-">(</>)</a> :: <ahref="HPath.html#t:RelC">RelC</a> r =><ahref="HPath.html#t:Path">Path</a> b -><ahref="HPath.html#t:Path
path separators <code>//</code>, no <code>..</code>, no <code>./</code>, no <code>~/</code>, etc.</p></div><divclass="subs instances"><pid="control.i:Path"class="caption collapser"onclick="toggleSection('i:Path')">Instances</p><divid="section.i:Path"class="show"><table><tr><tdclass="src"><ahref="https://hackage.haskell.org/package/base-4.7.0.2/docs/Data-Eq.html#t:Eq">Eq</a> (<ahref="HPath.html#t:Path">Path</a> b)</td><tdclass="doc"><p>ByteString equality.</p><p>The following property holds:</p><pre>show x == show y ≡ x == y</pre></td></tr><tr><tdclass="src"><ahref="https://hackage.haskell.org/package/base-4.7.0.2/docs/Data-Ord.html#t:Ord">Ord</a> (<ahref="HPath.html#t:Path">Path</a> b)</td><tdclass="doc"><p>ByteString ordering.</p><p>The following property holds:</p><pre>show x `compare` show y ≡ x `compare` y</pre></td></tr><tr><tdclass="src"><ahref="https://hackage.haskell.org/package/base-4.7.0.2/docs/Text-Show.html#t:Show">Show</a> (<ahref="HPath.html#t:Path">Path</a> b)</td><tdclass="doc"><p>Same as <code><ahref="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><tdclass="src"><ahref="https://hackage.haskell.org/package/deepseq-1.3.0.2/docs/Control-DeepSeq.html#t:NFData">NFData</a> (<ahref="HPath.html#t:Path">Path</a> b)</td><tdclass="doc empty"> </td></tr><tr><tdclass="src"><ahref="https://hackage.haskell.org/package/base-4.7.0.2/docs/Data-Typeable-Internal.html#t:Typeable">Typeable</a> (* -> *) <ahref="HPath.html#t:Path">Path</a></td><tdclass="doc empty"> </td></tr></table></div></div></div><divclass="top"><pclass="src"><spanclass="keyword">data</span><aname="t:Rel"class="def">Rel</a><ahref="src/HPath.html#Rel"class="link">Source</a></p><divclass="doc"><p>A relative path; one without a root.</p></div><divclass="subs instances"><pid="control.i:Rel"class="caption collapser"onclick="toggleSection('i:Rel')">Instances</p><divid="section.i:Rel"class="show"><table><tr><tdclass="src"><ahref="HPath.html#t:RelC">RelC</a><ahref="HPath.html#t:Rel">Rel</a></td><tdclass="doc empty"> </td></tr><tr><tdclass="src"><ahref="https://hackage.haskell.org/package/base-4.7.0.2/docs/Data-Typeable-Internal.html#t:Typeable">Typeable</a> * <ahref="HPath.html#t:Rel">Rel</a></td><tdclass="doc empty"> </td></tr></table></div></div></div><divclass="top"><pclass="src"><spanclass="keyword">data</span><aname="t:Fn"class="def">Fn</a><ahref="src/HPath.html#Fn"class="link">Source</a></p><divclass="doc"><p>A filename, without any <code><ahref="https://hackage.haskell.org/package/base-4.7.0.2/docs/Prelude.html#v:-47-">/</a></code>.</p></div><divclass="subs instances"><pid="control.i:Fn"class="caption collapser"onclick="toggleSection('i:Fn')">Instances</p><divid="section.i:Fn"class="show"><table><tr><tdclass="src"><ahref="HPath.html#t:RelC">RelC</a><ahref="HPath.html#t:Fn">Fn</a></td><tdclass="doc empty"> </td></tr><tr><tdclass="src"><ahref="https://hackage.haskell.org/package/base-4.7.0.2/docs/Data-Typeable-Internal.html#t:Typeable">Typeable</a> * <ahref="HPath.html#t:Fn">Fn</a></td><tdclass="doc empty"> </td></tr></table></div></div></div><divclass="top"><pclass="src"><spanclass="keyword">data</span><aname="t:PathParseException"class="def">PathParseException</a><ahref="src/HPath.html#PathParseException"class="link">Source</a></p><divclass="doc"><p>Exception when parsing a location.</p></div><divclass="subs instances"><pid="control.i:PathParseException"class="caption collapser"onclick="toggleSection('i:PathParseException')">Instances</p><divid="section.i:PathParseException"class="show"><table><tr><tdclass="src"><ahref="https://hackage.haskell.org/package/base-4.7.0.2/docs/Text-Show.html#t:Show">Show</a><ahref="HPath.html#t:PathParseException">PathParseException</a></td><tdclass="doc empty"> </td></tr><tr><tdclass="src"><ahref="https://hackage.haskell.org/package/base-4.7.0.2/docs/Control-Exception-Base.html#t:Ex
</pre></div></div><divclass="top"><pclass="src"><aname="v:parseFn"class="def">parseFn</a> :: MonadThrow m =><ahref="https://hackage.haskell.org/package/bytestring-0.10.4.0/docs/Data-ByteString.html#t:ByteString">ByteString</a> -> m (<ahref="HPath.html#t:Path">Path</a><ahref="HPath.html#t:Fn">Fn</a>) <ahref="src/HPath.html#parseFn"class="link">Source</a></p><divclass="doc"><p>Parses a filename. Filenames must not contain slashes.
Excludes <code><ahref="https://hackage.haskell.org/package/base-4.7.0.2/docs/Prelude.html#v:.">.</a></code> and '..'.</p><p>Throws: <code><ahref="HPath.html#t:PathParseException">PathParseException</a></code></p><preclass="screen"><codeclass="prompt">>>></code><strongclass="userinput"><code>parseFn "abc" :: Maybe (Path Fn)
</pre></div></div><divclass="top"><pclass="src"><aname="v:parseRel"class="def">parseRel</a> :: MonadThrow m =><ahref="https://hackage.haskell.org/package/bytestring-0.10.4.0/docs/Data-ByteString.html#t:ByteString">ByteString</a> -> m (<ahref="HPath.html#t:Path">Path</a><ahref="HPath.html#t:Rel">Rel</a>) <ahref="src/HPath.html#parseRel"class="link">Source</a></p><divclass="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><ahref="HPath.html#t:PathParseException">PathParseException</a></code></p><preclass="screen"><codeclass="prompt">>>></code><strongclass="userinput"><code>parseRel "abc" :: Maybe (Path Rel)
</pre></div></div><h1id="g:4">Path Conversion</h1><divclass="top"><pclass="src"><aname="v:fromAbs"class="def">fromAbs</a> :: <ahref="HPath.html#t:Path">Path</a><ahref="HPath.html#t:Abs">Abs</a> -><ahref="https://hackage.haskell.org/package/bytestring-0.10.4.0/docs/Data-ByteString.html#t:ByteString">ByteString</a><ahref="src/HPath.html#fromAbs"class="link">Source</a></p><divclass="doc"><p>Convert an absolute Path to a ByteString type.</p></div></div><divclass="top"><pclass="src"><aname="v:fromRel"class="def">fromRel</a> :: <ahref="HPath.html#t:RelC">RelC</a> r =><ahref="HPath.html#t:Path">Path</a> r -><ahref="https://hackage.haskell.org/package/bytestring-0.10.4.0/docs/Data-ByteString.html#t:ByteString">ByteString</a><ahref="src/HPath.html#fromRel"class="link">Source</a></p><divclass="doc"><p>Convert a relative Path to a ByteString type.</p></div></div><divclass="top"><pclass="src"><aname="v:toFilePath"class="def">toFilePath</a> :: <ahref="HPath.html#t:Path">Path</a> b -><ahref="https://hackage.haskell.org/package/bytestring-0.10.4.0/docs/Data-ByteString.html#t:ByteString">ByteString</a><ahref="src/HPath.html#toFilePath"class="link">Source</a></p><divclass="doc"><p>Convert any Path to a ByteString type.</p></div></div><h1id="g:5">Path Operations</h1><divclass="top"><pclass="src"><aname="v:-60--47--62-"class="def">(</>)</a> :: <ahref="HPath.html#t:RelC">RelC</a> r =><ahref="HPath.html#t:Path">Path</a> b -><ahref="HPath.html#t:Path">Path</a> r -><ahref="HPath.html#t:Path">Path</a> b <ahref="src/HPath.html#%3C%2F%3E"class="link">Source</a></p><divclass="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
</pre></div></div><divclass="top"><pclass="src"><aname="v:basename"class="def">basename</a> :: MonadThrow m =><ahref="HPath.html#t:Path">Path</a> b -> m (<ahref="HPath.html#t:Path">Path</a><ahref="HPath.html#t:Fn">Fn</a>) <ahref="src/HPath.html#basename"class="link">Source</a></p><divclass="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><ahref="HPath.html#t:PathException">PathException</a></code> if given the root path "/"</p><preclass="screen"><codeclass="prompt">>>></code><strongclass="userinput"><code>basename (MkPath "/abc/def/dod") :: Maybe (Path Fn)
</pre></div></div><divclass="top"><pclass="src"><aname="v:dirname"class="def">dirname</a> :: <ahref="HPath.html#t:Path">Path</a><ahref="HPath.html#t:Abs">Abs</a> -><ahref="HPath.html#t:Path">Path</a><ahref="HPath.html#t:Abs">Abs</a><ahref="src/HPath.html#dirname"class="link">Source</a></p><divclass="doc"><p>Extract the directory name of a path.</p><p>The following properties hold:</p><pre>dirname (p </> a) == dirname p</pre><preclass="screen"><codeclass="prompt">>>></code><strongclass="userinput"><code>dirname (MkPath "/abc/def/dod")
</pre></div></div><divclass="top"><pclass="src"><aname="v:isParentOf"class="def">isParentOf</a> :: <ahref="HPath.html#t:Path">Path</a> b -><ahref="HPath.html#t:Path">Path</a> b -><ahref="https://hackage.haskell.org/package/base-4.7.0.2/docs/Data-Bool.html#t:Bool">Bool</a><ahref="src/HPath.html#isParentOf"class="link">Source</a></p><divclass="doc"><p>Is p a parent of the given location? Implemented in terms of
<code><ahref="HPath.html#v:stripDir">stripDir</a></code>. The bases must match.</p><preclass="screen"><codeclass="prompt">>>></code><strongclass="userinput"><code>(MkPath "/lal/lad") `isParentOf` (MkPath "/lal/lad/fad")
</pre></div></div><divclass="top"><pclass="src"><aname="v:getAllParents"class="def">getAllParents</a> :: <ahref="HPath.html#t:Path">Path</a><ahref="HPath.html#t:Abs">Abs</a> -> [<ahref="HPath.html#t:Path">Path</a><ahref="HPath.html#t:Abs">Abs</a>] <ahref="src/HPath.html#getAllParents"class="link">Source</a></p><divclass="doc"><p>Get all parents of a path.</p><preclass="screen"><codeclass="prompt">>>></code><strongclass="userinput"><code>getAllParents (MkPath "/abs/def/dod")
</pre></div></div><divclass="top"><pclass="src"><aname="v:stripDir"class="def">stripDir</a> :: MonadThrow m =><ahref="HPath.html#t:Path">Path</a> b -><ahref="HPath.html#t:Path">Path</a> b -> m (<ahref="HPath.html#t:Path">Path</a><ahref="HPath.html#t:Rel">Rel</a>) <ahref="src/HPath.html#stripDir"class="link">Source</a></p><divclass="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><preclass="screen"><codeclass="prompt">>>></code><strongclass="userinput"><code>(MkPath "/lal/lad") `stripDir` (MkPath "/lal/lad/fad") :: Maybe (Path Rel)
</pre></div></div><h1id="g:6">Path IO helpers</h1><divclass="top"><pclass="src"><aname="v:withAbsPath"class="def">withAbsPath</a> :: <ahref="HPath.html#t:Path">Path</a><ahref="HPath.html#t:Abs">Abs</a> -> (<ahref="https://hackage.haskell.org/package/bytestring-0.10.4.0/docs/Data-ByteString.html#t:ByteString">ByteString</a> -><ahref="https://hackage.haskell.org/package/base-4.7.0.2/docs/System-IO.html#t:IO">IO</a> a) -><ahref="https://hackage.haskell.org/package/base-4.7.0.2/docs/System-IO.html#t:IO">IO</a> a <ahref="src/HPath.html#withAbsPath"class="link">Source</a></p></div><divclass="top"><pclass="src"><aname="v:withRelPath"class="def">withRelPath</a> :: <ahref="HPath.html#t:Path">Path</a><ahref="HPath.html#t:Rel">Rel</a> -> (<ahref="https://hackage.haskell.org/package/bytestring-0.10.4.0/docs/Data-ByteString.html#t:ByteString">ByteString</a> -><ahref="https://hackage.haskell.org/package/base-4.7.0.2/docs/System-IO.html#t:IO">IO</a> a) -><ahref="https://hackage.haskell.org/package/base-4.7.0.2/docs/System-IO.html#t:IO">IO</a> a <ahref="src/HPath.html#withRelPath"class="link">Source</a></p></div><divclass="top"><pclass="src"><aname="v:withFnPath"class="def">withFnPath</a> :: <ahref="HPath.html#t:Path">Path</a><ahref="HPath.html#t:Fn">Fn</a> -> (<ahref="https://hackage.haskell.org/package/bytestring-0.10.4.0/docs/Data-ByteString.html#t:ByteString">ByteString</a> -><ahref="https://hackage.haskell.org/package/base-4.7.0.2/docs/System-IO.html#t:IO">IO</a> a) -><ahref="https://hackage.haskell.org/package/base-4.7.0.2/docs/System-IO.html#t:IO">IO</a> a <ahref="src/HPath.html#withFnPath"class="link">Source</a></p></div></div></div><divid="footer"><p>Produced by <ahref="http://www.haskell.org/haddock/">Haddock</a> version 2.14.3</p></div></body></html>