<!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><scriptsrc="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"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.7.3: 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</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"><spanclass="keyword">pattern</span><ahref="#v:Path">Path</a> :: <spanclass="keyword">forall</span> a. <ahref="https://hackage.haskell.org/package/bytestring-0.10.8.1/docs/Data-ByteString.html#t:ByteString">ByteString</a> -><ahref="HPath.html#t:Path">Path</a> a</li><liclass="src short"><ahref="#v:parseAbs">parseAbs</a> :: MonadThrow m =><ahref="https://hackage.haskell.org/package/bytestring-0.10.8.1/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.8.1/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.8.1/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.8.1/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.8.1/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.8.1/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="
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 clearfix"><spanclass="inst-left"><spanid="control.i:id:Path:Eq:1"class="instance expander"onclick="toggleSection('i:id:Path:Eq:1')"></span><ahref="https://hackage.haskell.org/package/base-4.9.0.0/docs/Data-Eq.html#t:Eq">Eq</a> (<ahref="HPath.html#t:Path">Path</a> b)</span><ahref="src/HPath-Internal.html#line-30"class="link">Source</a><ahref="#t:Path"class="selflink">#</a></td><tdclass="doc"><p>ByteString equality.</p><p>The following property holds:</p><pre>show x == show y ≡ x == y</pre></td></tr><tr><tdcolspan="2"><divid="section.i:id:Path:Eq:1"class="inst-details hide"><divclass="subs methods"><pclass="caption">Methods</p><pclass="src"><ahref="#v:-61--61-">(==)</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.9.0.0/docs/Data-Bool.html#t:Bool">Bool</a><ahref="#v:-61--61-"class="selflink">#</a></p><pclass="src"><ahref="#v:-47--61-">(/=)</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.9.0.0/docs/Data-Bool.html#t:Bool">Bool</a><ahref="#v:-47--61-"class="selflink">#</a></p></div></div></td></tr><tr><tdclass="src clearfix"><spanclass="inst-left"><spanid="control.i:id:Path:Ord:2"class="instance expander"onclick="toggleSection('i:id:Path:Ord:2')"></span><ahref="https://hackage.haskell.org/package/base-4.9.0.0/docs/Data-Ord.html#t:Ord">Ord</a> (<ahref="HPath.html#t:Path">Path</a> b)</span><ahref="src/HPath-Internal.html#line-38"class="link">Source</a><ahref="#t:Path"class="selflink">#</a></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><tdcolspan="2"><divid="section.i:id:Path:Ord:2"class="inst-details hide"><divclass="subs methods"><pclass="caption">Methods</p><pclass="src"><ahref="#v:compare">compare</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.9.0.0/docs/Data-Ord.html#t:Ordering">Ordering</a><ahref="#v:compare"class="selflink">#</a></p><pclass="src"><ahref="#v:-60-">(<)</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.9.0.0/docs/Data-Bool.html#t:Bool">Bool</a><ahref="#v:-60-"class="selflink">#</a></p><pclass="src"><ahref="#v:-60--61-">(<=)</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.9.0.0/docs/Data-Bool.html#t:Bool">Bool</a><ahref="#v:-60--61-"class="selflink">#</a></p><pclass="src"><ahref="#v:-62-">(>)</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.9.0.0/docs/Data-Bool.html#t:Bool">Bool</a><ahref="#v:-62-"class="selflink">#</a></p><pclass="src"><ahref="#v:-62--61-">(>=)</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.9.0.0/docs/Data-Bool.html#t:Bool">Bool</a><ahref="#v:-62--61-"class="selflink">#</a></p><pclass="src"><ahref="#v:max">max</a> :: <ahref="HPath.html#t:Path">Path</a> b -><ahref="HPath.html#t:Path">Path</a> b -><ahref="HPath.html#t:Path">Path</a> b <ahref="#v:max"class="selflink">#</a></p><pclass="src"><ahref="#v:min">min</a> :: <ahref="HPath.html#t:Path">Path</a> b -><ahref="HPath.html#t:Path">Path</a> b -><ahref="HPath.html#t:Path">Path</a> b <ahref="#v:min"class="selflink">#</a></p></div></div></td
</pre></div></div><divclass="top"><pclass="src"><aid="v:parseFn"class="def">parseFn</a> :: MonadThrow m =><ahref="https://hackage.haskell.org/package/bytestring-0.10.8.1/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><ahref="#v:parseFn"class="selflink">#</a></p><divclass="doc"><p>Parses a filename. Filenames must not contain slashes.
Excludes <code><ahref="https://hackage.haskell.org/package/base-4.9.0.0/docs/Data-Function.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"><aid="v:parseRel"class="def">parseRel</a> :: MonadThrow m =><ahref="https://hackage.haskell.org/package/bytestring-0.10.8.1/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><ahref="#v:parseRel"class="selflink">#</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"><aid="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.8.1/docs/Data-ByteString.html#t:ByteString">ByteString</a><ahref="src/HPath.html#fromAbs"class="link">Source</a><ahref="#v:fromAbs"class="selflink">#</a></p><divclass="doc"><p>Convert an absolute Path to a ByteString type.</p></div></div><divclass="top"><pclass="src"><aid="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.8.1/docs/Data-ByteString.html#t:ByteString">ByteString</a><ahref="src/HPath.html#fromRel"class="link">Source</a><ahref="#v:fromRel"class="selflink">#</a></p><divclass="doc"><p>Convert a relative Path to a ByteString type.</p></div></div><divclass="top"><pclass="src"><aid="v:toFilePath"class="def">toFilePath</a> :: <ahref="HPath.html#t:Path">Path</a> b -><ahref="https://hackage.haskell.org/package/bytestring-0.10.8.1/docs/Data-ByteString.html#t:ByteString">ByteString</a><ahref="src/HPath.html#toFilePath"class="link">Source</a><ahref="#v:toFilePath"class="selflink">#</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"><aid="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><ahref="#v:-60--47--62-"class="selflink">#</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"><aid="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><ahref="#v:basename"class="selflink">#</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"><aid="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><ahref="#v:dirname"class="selflink">#</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"><aid="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.9.0.0/docs/Data-Bool.html#t:Bool">Bool</a><ahref="src/HPath.html#isParentOf"class="link">Source</a><ahref="#v:isParentOf"class="selflink">#</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"><aid="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><ahref="#v:getAllParents"class="selflink">#</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"><aid="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><ahref="#v:stripDir"class="selflink">#</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"><aid="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.8.1/docs/Data-ByteString.html#t:ByteString">ByteString</a> -><ahref="https://hackage.haskell.org/package/base-4.9.0.0/docs/System-IO.html#t:IO">IO</a> a) -><ahref="https://hackage.haskell.org/package/base-4.9.0.0/docs/System-IO.html#t:IO">IO</a> a <ahref="src/HPath.html#withAbsPath"class="link">Source</a><ahref="#v:withAbsPath"class="selflink">#</a></p></div><divclass="top"><pclass="src"><aid="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.8.1/docs/Data-ByteString.html#t:ByteString">ByteString</a> -><ahref="https://hackage.haskell.org/package/base-4.9.0.0/docs/System-IO.html#t:IO">IO</a> a) -><ahref="https://hackage.haskell.org/package/base-4.9.0.0/docs/System-IO.html#t:IO">IO</a> a <ahref="src/HPath.html#withRelPath"class="link">Source</a><ahref="#v:withRelPath"class="selflink">#</a></p></div><divclass="top"><pclass="src"><aid="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.8.1/docs/Data-ByteString.html#t:ByteString">ByteString</a> -><ahref="https://hackage.haskell.org/package/base-4.9.0.0/docs/System-IO.html#t:IO">IO</a> a) -><ahref="https://hackage.haskell.org/package/base-4.9.0.0/docs/System-IO.html#t:IO">IO</a> a <ahref="src/HPath.html#withFnPath"class="link">Source</a><ahref="#v:withFnPath"class="selflink">#</a></p></div></div></div><divid="footer"><p>Produced by <ahref="http://www.haskell.org/haddock/">Haddock</a> version 2.17.2</p></div></body></html>