Cabal-2.4.0.1: doc/API/Cabal/Distribution-Utils-Generic.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>Distribution.Utils.Generic</title><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean" /><link rel="stylesheet" type="text/css" href="quick-jump.css" /><script src="haddock-bundle.min.js" async="async" type="text/javascript"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"></script></head><body><div id="package-header"><ul class="links" id="page-menu"><li><a href="index.html">Contents</a></li><li><a href="doc-index.html">Index</a></li></ul><p class="caption">Cabal-2.4.0.1: A framework for packaging Haskell software</p></div><div id="content"><div id="module-header"><table class="info"><tr><th valign="top">Copyright</th><td>Isaac Jones Simon Marlow 2003-2004</td></tr><tr><th>License</th><td>BSD3
portions Copyright (c) 2007, Galois Inc.</td></tr><tr><th>Maintainer</th><td>cabal-devel@haskell.org</td></tr><tr><th>Portability</th><td>portable</td></tr><tr><th>Safe Haskell</th><td>None</td></tr><tr><th>Language</th><td>Haskell2010</td></tr></table><p class="caption">Distribution.Utils.Generic</p></div><div id="table-of-contents"><p class="caption">Contents</p><ul><li><a href="#g:1">reading and writing files safely</a></li><li><a href="#g:2">Unicode</a><ul><li><a href="#g:3">Conversions</a></li><li><a href="#g:4">File I/O</a></li><li><a href="#g:5">BOM</a></li><li><a href="#g:6">Misc</a></li></ul></li><li><a href="#g:7">generic utils</a></li><li><a href="#g:8">FilePath stuff</a></li></ul></div><div id="description"><p class="caption">Description</p><div class="doc"><p>A large and somewhat miscellaneous collection of utility functions used
throughout the rest of the Cabal lib and in other tools that use the Cabal
lib like <code>cabal-install</code>. It has a very simple set of logging actions. It
has low level functions for running programs, a bunch of wrappers for
various directory and file functions that do extra logging.</p></div></div><div id="synopsis"><details id="syn"><summary>Synopsis</summary><ul class="details-toggle" data-details-id="syn"><li class="src short"><a href="#v:withFileContents">withFileContents</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:FilePath" title="Distribution.Compat.Prelude.Internal">FilePath</a> -> (<a href="Distribution-Compat-Prelude-Internal.html#t:String" title="Distribution.Compat.Prelude.Internal">String</a> -> <a href="Distribution-Compat-Prelude-Internal.html#t:NoCallStackIO" title="Distribution.Compat.Prelude.Internal">NoCallStackIO</a> a) -> <a href="Distribution-Compat-Prelude-Internal.html#t:NoCallStackIO" title="Distribution.Compat.Prelude.Internal">NoCallStackIO</a> a</li><li class="src short"><a href="#v:writeFileAtomic">writeFileAtomic</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:FilePath" title="Distribution.Compat.Prelude.Internal">FilePath</a> -> <a href="file:///opt/ghc/8.4.3/share/doc/ghc-8.4.3/html/libraries/bytestring-0.10.8.2/Data-ByteString-Lazy.html#t:ByteString" title="Data.ByteString.Lazy">ByteString</a> -> <a href="Distribution-Compat-Prelude-Internal.html#t:NoCallStackIO" title="Distribution.Compat.Prelude.Internal">NoCallStackIO</a> ()</li><li class="src short"><a href="#v:fromUTF8BS">fromUTF8BS</a> :: <a href="file:///opt/ghc/8.4.3/share/doc/ghc-8.4.3/html/libraries/bytestring-0.10.8.2/Data-ByteString.html#t:ByteString" title="Data.ByteString">ByteString</a> -> <a href="Distribution-Compat-Prelude-Internal.html#t:String" title="Distribution.Compat.Prelude.Internal">String</a></li><li class="src short"><a href="#v:fromUTF8LBS">fromUTF8LBS</a> :: <a href="file:///opt/ghc/8.4.3/share/doc/ghc-8.4.3/html/libraries/bytestring-0.10.8.2/Data-ByteString-Lazy.html#t:ByteString" title="Data.ByteString.Lazy">ByteString</a> -> <a href="Distribution-Compat-Prelude-Internal.html#t:String" title="Distribution.Compat.Prelude.Internal">String</a></li><li class="src short"><a href="#v:toUTF8BS">toUTF8BS</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:String" title="Distribution.Compat.Prelude.Internal">String</a> -> <a href="file:///opt/ghc/8.4.3/share/doc/ghc-8.4.3/html/libraries/bytestring-0.10.8.2/Data-ByteString.html#t:ByteString" title="Data.ByteString">ByteString</a></li><li class="src short"><a href="#v:toUTF8LBS">toUTF8LBS</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:String" title="Distribution.Compat.Prelude.Internal">String</a> -> <a href="file:///opt/ghc/8.4.3/share/doc/ghc-8.4.3/html/libraries/bytestring-0.10.8.2/Data-ByteString-Lazy.html#t:ByteString" title="Data.ByteString.Lazy">ByteString</a></li><li class="src short"><a href="#v:validateUTF8">validateUTF8</a> :: <a href="file:///opt/ghc/8.4.3/share/doc/ghc-8.4.3/html/libraries/bytestring-0.10.8.2/Data-ByteString.html#t:ByteString" title="Data.ByteString">ByteString</a> -> <a href="Distribution-Compat-Prelude-Internal.html#t:Maybe" title="Distribution.Compat.Prelude.Internal">Maybe</a> <a href="Distribution-Compat-Prelude-Internal.html#t:Int" title="Distribution.Compat.Prelude.Internal">Int</a></li><li class="src short"><a href="#v:readUTF8File">readUTF8File</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:FilePath" title="Distribution.Compat.Prelude.Internal">FilePath</a> -> <a href="Distribution-Compat-Prelude-Internal.html#t:NoCallStackIO" title="Distribution.Compat.Prelude.Internal">NoCallStackIO</a> <a href="Distribution-Compat-Prelude-Internal.html#t:String" title="Distribution.Compat.Prelude.Internal">String</a></li><li class="src short"><a href="#v:withUTF8FileContents">withUTF8FileContents</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:FilePath" title="Distribution.Compat.Prelude.Internal">FilePath</a> -> (<a href="Distribution-Compat-Prelude-Internal.html#t:String" title="Distribution.Compat.Prelude.Internal">String</a> -> <a href="Distribution-Compat-Prelude-Internal.html#t:IO" title="Distribution.Compat.Prelude.Internal">IO</a> a) -> <a href="Distribution-Compat-Prelude-Internal.html#t:IO" title="Distribution.Compat.Prelude.Internal">IO</a> a</li><li class="src short"><a href="#v:writeUTF8File">writeUTF8File</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:FilePath" title="Distribution.Compat.Prelude.Internal">FilePath</a> -> <a href="Distribution-Compat-Prelude-Internal.html#t:String" title="Distribution.Compat.Prelude.Internal">String</a> -> <a href="Distribution-Compat-Prelude-Internal.html#t:NoCallStackIO" title="Distribution.Compat.Prelude.Internal">NoCallStackIO</a> ()</li><li class="src short"><a href="#v:ignoreBOM">ignoreBOM</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:String" title="Distribution.Compat.Prelude.Internal">String</a> -> <a href="Distribution-Compat-Prelude-Internal.html#t:String" title="Distribution.Compat.Prelude.Internal">String</a></li><li class="src short"><a href="#v:normaliseLineEndings">normaliseLineEndings</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:String" title="Distribution.Compat.Prelude.Internal">String</a> -> <a href="Distribution-Compat-Prelude-Internal.html#t:String" title="Distribution.Compat.Prelude.Internal">String</a></li><li class="src short"><a href="#v:dropWhileEndLE">dropWhileEndLE</a> :: (a -> <a href="Distribution-Compat-Prelude-Internal.html#t:Bool" title="Distribution.Compat.Prelude.Internal">Bool</a>) -> [a] -> [a]</li><li class="src short"><a href="#v:takeWhileEndLE">takeWhileEndLE</a> :: (a -> <a href="Distribution-Compat-Prelude-Internal.html#t:Bool" title="Distribution.Compat.Prelude.Internal">Bool</a>) -> [a] -> [a]</li><li class="src short"><a href="#v:equating">equating</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:Eq" title="Distribution.Compat.Prelude.Internal">Eq</a> a => (b -> a) -> b -> b -> <a href="Distribution-Compat-Prelude-Internal.html#t:Bool" title="Distribution.Compat.Prelude.Internal">Bool</a></li><li class="src short"><a href="#v:comparing">comparing</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:Ord" title="Distribution.Compat.Prelude.Internal">Ord</a> a => (b -> a) -> b -> b -> <a href="Distribution-Compat-Prelude-Internal.html#t:Ordering" title="Distribution.Compat.Prelude.Internal">Ordering</a></li><li class="src short"><a href="#v:isInfixOf">isInfixOf</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:Eq" title="Distribution.Compat.Prelude.Internal">Eq</a> a => [a] -> [a] -> <a href="Distribution-Compat-Prelude-Internal.html#t:Bool" title="Distribution.Compat.Prelude.Internal">Bool</a></li><li class="src short"><a href="#v:intercalate">intercalate</a> :: [a] -> [[a]] -> [a]</li><li class="src short"><a href="#v:lowercase">lowercase</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:String" title="Distribution.Compat.Prelude.Internal">String</a> -> <a href="Distribution-Compat-Prelude-Internal.html#t:String" title="Distribution.Compat.Prelude.Internal">String</a></li><li class="src short"><a href="#v:isAscii">isAscii</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:Char" title="Distribution.Compat.Prelude.Internal">Char</a> -> <a href="Distribution-Compat-Prelude-Internal.html#t:Bool" title="Distribution.Compat.Prelude.Internal">Bool</a></li><li class="src short"><a href="#v:isAsciiAlpha">isAsciiAlpha</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:Char" title="Distribution.Compat.Prelude.Internal">Char</a> -> <a href="Distribution-Compat-Prelude-Internal.html#t:Bool" title="Distribution.Compat.Prelude.Internal">Bool</a></li><li class="src short"><a href="#v:isAsciiAlphaNum">isAsciiAlphaNum</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:Char" title="Distribution.Compat.Prelude.Internal">Char</a> -> <a href="Distribution-Compat-Prelude-Internal.html#t:Bool" title="Distribution.Compat.Prelude.Internal">Bool</a></li><li class="src short"><a href="#v:listUnion">listUnion</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:Ord" title="Distribution.Compat.Prelude.Internal">Ord</a> a => [a] -> [a] -> [a]</li><li class="src short"><a href="#v:listUnionRight">listUnionRight</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:Ord" title="Distribution.Compat.Prelude.Internal">Ord</a> a => [a] -> [a] -> [a]</li><li class="src short"><a href="#v:ordNub">ordNub</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:Ord" title="Distribution.Compat.Prelude.Internal">Ord</a> a => [a] -> [a]</li><li class="src short"><a href="#v:ordNubBy">ordNubBy</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:Ord" title="Distribution.Compat.Prelude.Internal">Ord</a> b => (a -> b) -> [a] -> [a]</li><li class="src short"><a href="#v:ordNubRight">ordNubRight</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:Ord" title="Distribution.Compat.Prelude.Internal">Ord</a> a => [a] -> [a]</li><li class="src short"><a href="#v:safeTail">safeTail</a> :: [a] -> [a]</li><li class="src short"><a href="#v:unintersperse">unintersperse</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:Char" title="Distribution.Compat.Prelude.Internal">Char</a> -> <a href="Distribution-Compat-Prelude-Internal.html#t:String" title="Distribution.Compat.Prelude.Internal">String</a> -> [<a href="Distribution-Compat-Prelude-Internal.html#t:String" title="Distribution.Compat.Prelude.Internal">String</a>]</li><li class="src short"><a href="#v:wrapText">wrapText</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:String" title="Distribution.Compat.Prelude.Internal">String</a> -> <a href="Distribution-Compat-Prelude-Internal.html#t:String" title="Distribution.Compat.Prelude.Internal">String</a></li><li class="src short"><a href="#v:wrapLine">wrapLine</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:Int" title="Distribution.Compat.Prelude.Internal">Int</a> -> [<a href="Distribution-Compat-Prelude-Internal.html#t:String" title="Distribution.Compat.Prelude.Internal">String</a>] -> [[<a href="Distribution-Compat-Prelude-Internal.html#t:String" title="Distribution.Compat.Prelude.Internal">String</a>]]</li><li class="src short"><a href="#v:unfoldrM">unfoldrM</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:Monad" title="Distribution.Compat.Prelude.Internal">Monad</a> m => (b -> m (<a href="Distribution-Compat-Prelude-Internal.html#t:Maybe" title="Distribution.Compat.Prelude.Internal">Maybe</a> (a, b))) -> b -> m [a]</li><li class="src short"><a href="#v:spanMaybe">spanMaybe</a> :: (a -> <a href="Distribution-Compat-Prelude-Internal.html#t:Maybe" title="Distribution.Compat.Prelude.Internal">Maybe</a> b) -> [a] -> ([b], [a])</li><li class="src short"><a href="#v:breakMaybe">breakMaybe</a> :: (a -> <a href="Distribution-Compat-Prelude-Internal.html#t:Maybe" title="Distribution.Compat.Prelude.Internal">Maybe</a> b) -> [a] -> ([a], <a href="Distribution-Compat-Prelude-Internal.html#t:Maybe" title="Distribution.Compat.Prelude.Internal">Maybe</a> (b, [a]))</li><li class="src short"><a href="#v:isAbsoluteOnAnyPlatform">isAbsoluteOnAnyPlatform</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:FilePath" title="Distribution.Compat.Prelude.Internal">FilePath</a> -> <a href="Distribution-Compat-Prelude-Internal.html#t:Bool" title="Distribution.Compat.Prelude.Internal">Bool</a></li><li class="src short"><a href="#v:isRelativeOnAnyPlatform">isRelativeOnAnyPlatform</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:FilePath" title="Distribution.Compat.Prelude.Internal">FilePath</a> -> <a href="Distribution-Compat-Prelude-Internal.html#t:Bool" title="Distribution.Compat.Prelude.Internal">Bool</a></li></ul></details></div><div id="interface"><a href="#g:1" id="g:1"><h1>reading and writing files safely</h1></a><div class="top"><p class="src"><a id="v:withFileContents" class="def">withFileContents</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:FilePath" title="Distribution.Compat.Prelude.Internal">FilePath</a> -> (<a href="Distribution-Compat-Prelude-Internal.html#t:String" title="Distribution.Compat.Prelude.Internal">String</a> -> <a href="Distribution-Compat-Prelude-Internal.html#t:NoCallStackIO" title="Distribution.Compat.Prelude.Internal">NoCallStackIO</a> a) -> <a href="Distribution-Compat-Prelude-Internal.html#t:NoCallStackIO" title="Distribution.Compat.Prelude.Internal">NoCallStackIO</a> a <a href="#v:withFileContents" class="selflink">#</a></p><div class="doc"><p>Gets the contents of a file, but guarantee that it gets closed.</p><p>The file is read lazily but if it is not fully consumed by the action then
the remaining input is truncated and the file is closed.</p></div></div><div class="top"><p class="src"><a id="v:writeFileAtomic" class="def">writeFileAtomic</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:FilePath" title="Distribution.Compat.Prelude.Internal">FilePath</a> -> <a href="file:///opt/ghc/8.4.3/share/doc/ghc-8.4.3/html/libraries/bytestring-0.10.8.2/Data-ByteString-Lazy.html#t:ByteString" title="Data.ByteString.Lazy">ByteString</a> -> <a href="Distribution-Compat-Prelude-Internal.html#t:NoCallStackIO" title="Distribution.Compat.Prelude.Internal">NoCallStackIO</a> () <a href="#v:writeFileAtomic" class="selflink">#</a></p><div class="doc"><p>Writes a file atomically.</p><p>The file is either written successfully or an IO exception is raised and
the original file is left unchanged.</p><p>On windows it is not possible to delete a file that is open by a process.
This case will give an IO exception but the atomic property is not affected.</p></div></div><a href="#g:2" id="g:2"><h1>Unicode</h1></a><a href="#g:3" id="g:3"><h2>Conversions</h2></a><div class="top"><p class="src"><a id="v:fromUTF8BS" class="def">fromUTF8BS</a> :: <a href="file:///opt/ghc/8.4.3/share/doc/ghc-8.4.3/html/libraries/bytestring-0.10.8.2/Data-ByteString.html#t:ByteString" title="Data.ByteString">ByteString</a> -> <a href="Distribution-Compat-Prelude-Internal.html#t:String" title="Distribution.Compat.Prelude.Internal">String</a> <a href="#v:fromUTF8BS" class="selflink">#</a></p><div class="doc"><p>Decode <code><a href="Distribution-Compat-Prelude-Internal.html#t:String" title="Distribution.Compat.Prelude.Internal">String</a></code> from UTF8-encoded <code><a href="file:///opt/ghc/8.4.3/share/doc/ghc-8.4.3/html/libraries/bytestring-0.10.8.2/Data-ByteString-Lazy.html#t:ByteString" title="Data.ByteString.Lazy">ByteString</a></code></p><p>Invalid data in the UTF8 stream (this includes code-points <code>U+D800</code>
through <code>U+DFFF</code>) will be decoded as the replacement character (<code>U+FFFD</code>).</p></div></div><div class="top"><p class="src"><a id="v:fromUTF8LBS" class="def">fromUTF8LBS</a> :: <a href="file:///opt/ghc/8.4.3/share/doc/ghc-8.4.3/html/libraries/bytestring-0.10.8.2/Data-ByteString-Lazy.html#t:ByteString" title="Data.ByteString.Lazy">ByteString</a> -> <a href="Distribution-Compat-Prelude-Internal.html#t:String" title="Distribution.Compat.Prelude.Internal">String</a> <a href="#v:fromUTF8LBS" class="selflink">#</a></p><div class="doc"><p>Variant of <code><a href="Distribution-Utils-Generic.html#v:fromUTF8BS" title="Distribution.Utils.Generic">fromUTF8BS</a></code> for lazy <code><a href="file:///opt/ghc/8.4.3/share/doc/ghc-8.4.3/html/libraries/bytestring-0.10.8.2/Data-ByteString-Lazy.html#t:ByteString" title="Data.ByteString.Lazy">ByteString</a></code>s</p></div></div><div class="top"><p class="src"><a id="v:toUTF8BS" class="def">toUTF8BS</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:String" title="Distribution.Compat.Prelude.Internal">String</a> -> <a href="file:///opt/ghc/8.4.3/share/doc/ghc-8.4.3/html/libraries/bytestring-0.10.8.2/Data-ByteString.html#t:ByteString" title="Data.ByteString">ByteString</a> <a href="#v:toUTF8BS" class="selflink">#</a></p><div class="doc"><p>Encode <code><a href="Distribution-Compat-Prelude-Internal.html#t:String" title="Distribution.Compat.Prelude.Internal">String</a></code> to to UTF8-encoded <code><a href="file:///opt/ghc/8.4.3/share/doc/ghc-8.4.3/html/libraries/bytestring-0.10.8.2/Data-ByteString.html#t:ByteString" title="Data.ByteString">ByteString</a></code></p><p>Code-points in the <code>U+D800</code>-<code>U+DFFF</code> range will be encoded
as the replacement character (i.e. <code>U+FFFD</code>).</p></div></div><div class="top"><p class="src"><a id="v:toUTF8LBS" class="def">toUTF8LBS</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:String" title="Distribution.Compat.Prelude.Internal">String</a> -> <a href="file:///opt/ghc/8.4.3/share/doc/ghc-8.4.3/html/libraries/bytestring-0.10.8.2/Data-ByteString-Lazy.html#t:ByteString" title="Data.ByteString.Lazy">ByteString</a> <a href="#v:toUTF8LBS" class="selflink">#</a></p><div class="doc"><p>Variant of <code><a href="Distribution-Utils-Generic.html#v:toUTF8BS" title="Distribution.Utils.Generic">toUTF8BS</a></code> for lazy <code><a href="file:///opt/ghc/8.4.3/share/doc/ghc-8.4.3/html/libraries/bytestring-0.10.8.2/Data-ByteString-Lazy.html#t:ByteString" title="Data.ByteString.Lazy">ByteString</a></code>s</p></div></div><div class="top"><p class="src"><a id="v:validateUTF8" class="def">validateUTF8</a> :: <a href="file:///opt/ghc/8.4.3/share/doc/ghc-8.4.3/html/libraries/bytestring-0.10.8.2/Data-ByteString.html#t:ByteString" title="Data.ByteString">ByteString</a> -> <a href="Distribution-Compat-Prelude-Internal.html#t:Maybe" title="Distribution.Compat.Prelude.Internal">Maybe</a> <a href="Distribution-Compat-Prelude-Internal.html#t:Int" title="Distribution.Compat.Prelude.Internal">Int</a> <a href="#v:validateUTF8" class="selflink">#</a></p><div class="doc"><p>Check that strict <code>ByteString</code> is valid UTF8. Returns 'Just offset' if it's not.</p></div></div><a href="#g:4" id="g:4"><h2>File I/O</h2></a><div class="top"><p class="src"><a id="v:readUTF8File" class="def">readUTF8File</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:FilePath" title="Distribution.Compat.Prelude.Internal">FilePath</a> -> <a href="Distribution-Compat-Prelude-Internal.html#t:NoCallStackIO" title="Distribution.Compat.Prelude.Internal">NoCallStackIO</a> <a href="Distribution-Compat-Prelude-Internal.html#t:String" title="Distribution.Compat.Prelude.Internal">String</a> <a href="#v:readUTF8File" class="selflink">#</a></p><div class="doc"><p>Reads a UTF8 encoded text file as a Unicode String</p><p>Reads lazily using ordinary <code><a href="Distribution-Compat-Prelude-Internal.html#v:readFile" title="Distribution.Compat.Prelude.Internal">readFile</a></code>.</p></div></div><div class="top"><p class="src"><a id="v:withUTF8FileContents" class="def">withUTF8FileContents</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:FilePath" title="Distribution.Compat.Prelude.Internal">FilePath</a> -> (<a href="Distribution-Compat-Prelude-Internal.html#t:String" title="Distribution.Compat.Prelude.Internal">String</a> -> <a href="Distribution-Compat-Prelude-Internal.html#t:IO" title="Distribution.Compat.Prelude.Internal">IO</a> a) -> <a href="Distribution-Compat-Prelude-Internal.html#t:IO" title="Distribution.Compat.Prelude.Internal">IO</a> a <a href="#v:withUTF8FileContents" class="selflink">#</a></p><div class="doc"><p>Reads a UTF8 encoded text file as a Unicode String</p><p>Same behaviour as <code><a href="Distribution-Utils-Generic.html#v:withFileContents" title="Distribution.Utils.Generic">withFileContents</a></code>.</p></div></div><div class="top"><p class="src"><a id="v:writeUTF8File" class="def">writeUTF8File</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:FilePath" title="Distribution.Compat.Prelude.Internal">FilePath</a> -> <a href="Distribution-Compat-Prelude-Internal.html#t:String" title="Distribution.Compat.Prelude.Internal">String</a> -> <a href="Distribution-Compat-Prelude-Internal.html#t:NoCallStackIO" title="Distribution.Compat.Prelude.Internal">NoCallStackIO</a> () <a href="#v:writeUTF8File" class="selflink">#</a></p><div class="doc"><p>Writes a Unicode String as a UTF8 encoded text file.</p><p>Uses <code><a href="Distribution-Utils-Generic.html#v:writeFileAtomic" title="Distribution.Utils.Generic">writeFileAtomic</a></code>, so provides the same guarantees.</p></div></div><a href="#g:5" id="g:5"><h2>BOM</h2></a><div class="top"><p class="src"><a id="v:ignoreBOM" class="def">ignoreBOM</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:String" title="Distribution.Compat.Prelude.Internal">String</a> -> <a href="Distribution-Compat-Prelude-Internal.html#t:String" title="Distribution.Compat.Prelude.Internal">String</a> <a href="#v:ignoreBOM" class="selflink">#</a></p><div class="doc"><p>Ignore a Unicode byte order mark (BOM) at the beginning of the input</p></div></div><a href="#g:6" id="g:6"><h2>Misc</h2></a><div class="top"><p class="src"><a id="v:normaliseLineEndings" class="def">normaliseLineEndings</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:String" title="Distribution.Compat.Prelude.Internal">String</a> -> <a href="Distribution-Compat-Prelude-Internal.html#t:String" title="Distribution.Compat.Prelude.Internal">String</a> <a href="#v:normaliseLineEndings" class="selflink">#</a></p><div class="doc"><p>Fix different systems silly line ending conventions</p></div></div><a href="#g:7" id="g:7"><h1>generic utils</h1></a><div class="top"><p class="src"><a id="v:dropWhileEndLE" class="def">dropWhileEndLE</a> :: (a -> <a href="Distribution-Compat-Prelude-Internal.html#t:Bool" title="Distribution.Compat.Prelude.Internal">Bool</a>) -> [a] -> [a] <a href="#v:dropWhileEndLE" class="selflink">#</a></p><div class="doc"><p><code>dropWhileEndLE p</code> is equivalent to <code>reverse . dropWhile p . reverse</code>, but
quite a bit faster. The difference between "Data.List.dropWhileEnd" and this
version is that the one in <a href="file:///opt/ghc/8.4.3/share/doc/ghc-8.4.3/html/libraries/base-4.11.1.0/Data-List.html">Data.List</a> is strict in elements, but spine-lazy,
while this one is spine-strict but lazy in elements. That's what <code>LE</code> stands
for - "lazy in elements".</p><p>Example:</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>tail $ Data.List.dropWhileEnd (<3) [undefined, 5, 4, 3, 2, 1]
</code></strong>*** Exception: Prelude.undefined
...
</pre><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>tail $ dropWhileEndLE (<3) [undefined, 5, 4, 3, 2, 1]
</code></strong>[5,4,3]
</pre><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>take 3 $ Data.List.dropWhileEnd (<3) [5, 4, 3, 2, 1, undefined]
</code></strong>[5,4,3]
</pre><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>take 3 $ dropWhileEndLE (<3) [5, 4, 3, 2, 1, undefined]
</code></strong>*** Exception: Prelude.undefined
...
</pre></div></div><div class="top"><p class="src"><a id="v:takeWhileEndLE" class="def">takeWhileEndLE</a> :: (a -> <a href="Distribution-Compat-Prelude-Internal.html#t:Bool" title="Distribution.Compat.Prelude.Internal">Bool</a>) -> [a] -> [a] <a href="#v:takeWhileEndLE" class="selflink">#</a></p><div class="doc"><p><code>takeWhileEndLE p</code> is equivalent to <code>reverse . takeWhile p . reverse</code>, but
is usually faster (as well as being easier to read).</p></div></div><div class="top"><p class="src"><a id="v:equating" class="def">equating</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:Eq" title="Distribution.Compat.Prelude.Internal">Eq</a> a => (b -> a) -> b -> b -> <a href="Distribution-Compat-Prelude-Internal.html#t:Bool" title="Distribution.Compat.Prelude.Internal">Bool</a> <a href="#v:equating" class="selflink">#</a></p></div><div class="top"><p class="src"><a id="v:comparing" class="def">comparing</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:Ord" title="Distribution.Compat.Prelude.Internal">Ord</a> a => (b -> a) -> b -> b -> <a href="Distribution-Compat-Prelude-Internal.html#t:Ordering" title="Distribution.Compat.Prelude.Internal">Ordering</a> <a href="#v:comparing" class="selflink">#</a></p><div class="doc"><pre>comparing p x y = compare (p x) (p y)</pre><p>Useful combinator for use in conjunction with the <code>xxxBy</code> family
of functions from <a href="file:///opt/ghc/8.4.3/share/doc/ghc-8.4.3/html/libraries/base-4.11.1.0/Data-List.html">Data.List</a>, for example:</p><pre> ... sortBy (comparing fst) ...</pre></div></div><div class="top"><p class="src"><a id="v:isInfixOf" class="def">isInfixOf</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:Eq" title="Distribution.Compat.Prelude.Internal">Eq</a> a => [a] -> [a] -> <a href="Distribution-Compat-Prelude-Internal.html#t:Bool" title="Distribution.Compat.Prelude.Internal">Bool</a> <a href="#v:isInfixOf" class="selflink">#</a></p><div class="doc"><p>The <code><a href="Distribution-Utils-Generic.html#v:isInfixOf" title="Distribution.Utils.Generic">isInfixOf</a></code> function takes two lists and returns <code><a href="Distribution-Compat-Prelude-Internal.html#v:True" title="Distribution.Compat.Prelude.Internal">True</a></code>
iff the first list is contained, wholly and intact,
anywhere within the second.</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>isInfixOf "Haskell" "I really like Haskell."
</code></strong>True
</pre><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>isInfixOf "Ial" "I really like Haskell."
</code></strong>False
</pre></div></div><div class="top"><p class="src"><a id="v:intercalate" class="def">intercalate</a> :: [a] -> [[a]] -> [a] <a href="#v:intercalate" class="selflink">#</a></p><div class="doc"><p><code><a href="Distribution-Utils-Generic.html#v:intercalate" title="Distribution.Utils.Generic">intercalate</a></code> <code>xs xss</code> is equivalent to <code>(<code><a href="file:///opt/ghc/8.4.3/share/doc/ghc-8.4.3/html/libraries/base-4.11.1.0/GHC-OldList.html#v:concat" title="GHC.OldList">concat</a></code> (<code><a href="Distribution-Compat-Prelude-Internal.html#v:intersperse" title="Distribution.Compat.Prelude.Internal">intersperse</a></code> xs xss))</code>.
It inserts the list <code>xs</code> in between the lists in <code>xss</code> and concatenates the
result.</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>intercalate ", " ["Lorem", "ipsum", "dolor"]
</code></strong>"Lorem, ipsum, dolor"
</pre></div></div><div class="top"><p class="src"><a id="v:lowercase" class="def">lowercase</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:String" title="Distribution.Compat.Prelude.Internal">String</a> -> <a href="Distribution-Compat-Prelude-Internal.html#t:String" title="Distribution.Compat.Prelude.Internal">String</a> <a href="#v:lowercase" class="selflink">#</a></p><div class="doc"><p>Lower case string</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>lowercase "Foobar"
</code></strong>"foobar"
</pre></div></div><div class="top"><p class="src"><a id="v:isAscii" class="def">isAscii</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:Char" title="Distribution.Compat.Prelude.Internal">Char</a> -> <a href="Distribution-Compat-Prelude-Internal.html#t:Bool" title="Distribution.Compat.Prelude.Internal">Bool</a> <a href="#v:isAscii" class="selflink">#</a></p><div class="doc"><p>Ascii characters</p></div></div><div class="top"><p class="src"><a id="v:isAsciiAlpha" class="def">isAsciiAlpha</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:Char" title="Distribution.Compat.Prelude.Internal">Char</a> -> <a href="Distribution-Compat-Prelude-Internal.html#t:Bool" title="Distribution.Compat.Prelude.Internal">Bool</a> <a href="#v:isAsciiAlpha" class="selflink">#</a></p><div class="doc"><p>Ascii letters.</p></div></div><div class="top"><p class="src"><a id="v:isAsciiAlphaNum" class="def">isAsciiAlphaNum</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:Char" title="Distribution.Compat.Prelude.Internal">Char</a> -> <a href="Distribution-Compat-Prelude-Internal.html#t:Bool" title="Distribution.Compat.Prelude.Internal">Bool</a> <a href="#v:isAsciiAlphaNum" class="selflink">#</a></p><div class="doc"><p>Ascii letters and digits.</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>isAsciiAlphaNum 'a'
</code></strong>True
</pre><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>isAsciiAlphaNum 'ä'
</code></strong>False
</pre></div></div><div class="top"><p class="src"><a id="v:listUnion" class="def">listUnion</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:Ord" title="Distribution.Compat.Prelude.Internal">Ord</a> a => [a] -> [a] -> [a] <a href="#v:listUnion" class="selflink">#</a></p><div class="doc"><p>Like "Data.List.union", but has <code>O(n log n)</code> complexity instead of
<code>O(n^2)</code>.</p></div></div><div class="top"><p class="src"><a id="v:listUnionRight" class="def">listUnionRight</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:Ord" title="Distribution.Compat.Prelude.Internal">Ord</a> a => [a] -> [a] -> [a] <a href="#v:listUnionRight" class="selflink">#</a></p><div class="doc"><p>A right-biased version of <code><a href="Distribution-Utils-Generic.html#v:listUnion" title="Distribution.Utils.Generic">listUnion</a></code>.</p><p>Example:</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>listUnion [1,2,3,4,3] [2,1,1]
</code></strong>[1,2,3,4,3]
</pre><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>listUnionRight [1,2,3,4,3] [2,1,1]
</code></strong>[4,3,2,1,1]
</pre></div></div><div class="top"><p class="src"><a id="v:ordNub" class="def">ordNub</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:Ord" title="Distribution.Compat.Prelude.Internal">Ord</a> a => [a] -> [a] <a href="#v:ordNub" class="selflink">#</a></p><div class="doc"><p>Like <code><a href="file:///opt/ghc/8.4.3/share/doc/ghc-8.4.3/html/libraries/base-4.11.1.0/Data-List.html#v:nub" title="Data.List">nub</a></code>, but has <code>O(n log n)</code> complexity instead of
<code>O(n^2)</code>. Code for <code><a href="Distribution-Utils-Generic.html#v:ordNub" title="Distribution.Utils.Generic">ordNub</a></code> and <code><a href="Distribution-Utils-Generic.html#v:listUnion" title="Distribution.Utils.Generic">listUnion</a></code> taken from Niklas Hambüchen's
<a href="http://github.com/nh2/haskell-ordnub">ordnub</a> package.</p></div></div><div class="top"><p class="src"><a id="v:ordNubBy" class="def">ordNubBy</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:Ord" title="Distribution.Compat.Prelude.Internal">Ord</a> b => (a -> b) -> [a] -> [a] <a href="#v:ordNubBy" class="selflink">#</a></p><div class="doc"><p>Like <code><a href="Distribution-Utils-Generic.html#v:ordNub" title="Distribution.Utils.Generic">ordNub</a></code> and <code><a href="file:///opt/ghc/8.4.3/share/doc/ghc-8.4.3/html/libraries/base-4.11.1.0/Data-List.html#v:nubBy" title="Data.List">nubBy</a></code>. Selects a key for each element and
takes the nub based on that key.</p></div></div><div class="top"><p class="src"><a id="v:ordNubRight" class="def">ordNubRight</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:Ord" title="Distribution.Compat.Prelude.Internal">Ord</a> a => [a] -> [a] <a href="#v:ordNubRight" class="selflink">#</a></p><div class="doc"><p>A right-biased version of <code><a href="Distribution-Utils-Generic.html#v:ordNub" title="Distribution.Utils.Generic">ordNub</a></code>.</p><p>Example:</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>ordNub [1,2,1] :: [Int]
</code></strong>[1,2]
</pre><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>ordNubRight [1,2,1] :: [Int]
</code></strong>[2,1]
</pre></div></div><div class="top"><p class="src"><a id="v:safeTail" class="def">safeTail</a> :: [a] -> [a] <a href="#v:safeTail" class="selflink">#</a></p><div class="doc"><p>A total variant of <code><a href="Distribution-Compat-Prelude-Internal.html#v:tail" title="Distribution.Compat.Prelude.Internal">tail</a></code>.</p></div></div><div class="top"><p class="src"><a id="v:unintersperse" class="def">unintersperse</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:Char" title="Distribution.Compat.Prelude.Internal">Char</a> -> <a href="Distribution-Compat-Prelude-Internal.html#t:String" title="Distribution.Compat.Prelude.Internal">String</a> -> [<a href="Distribution-Compat-Prelude-Internal.html#t:String" title="Distribution.Compat.Prelude.Internal">String</a>] <a href="#v:unintersperse" class="selflink">#</a></p></div><div class="top"><p class="src"><a id="v:wrapText" class="def">wrapText</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:String" title="Distribution.Compat.Prelude.Internal">String</a> -> <a href="Distribution-Compat-Prelude-Internal.html#t:String" title="Distribution.Compat.Prelude.Internal">String</a> <a href="#v:wrapText" class="selflink">#</a></p><div class="doc"><p>Wraps text to the default line width. Existing newlines are preserved.</p></div></div><div class="top"><p class="src"><a id="v:wrapLine" class="def">wrapLine</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:Int" title="Distribution.Compat.Prelude.Internal">Int</a> -> [<a href="Distribution-Compat-Prelude-Internal.html#t:String" title="Distribution.Compat.Prelude.Internal">String</a>] -> [[<a href="Distribution-Compat-Prelude-Internal.html#t:String" title="Distribution.Compat.Prelude.Internal">String</a>]] <a href="#v:wrapLine" class="selflink">#</a></p><div class="doc"><p>Wraps a list of words to a list of lines of words of a particular width.</p></div></div><div class="top"><p class="src"><a id="v:unfoldrM" class="def">unfoldrM</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:Monad" title="Distribution.Compat.Prelude.Internal">Monad</a> m => (b -> m (<a href="Distribution-Compat-Prelude-Internal.html#t:Maybe" title="Distribution.Compat.Prelude.Internal">Maybe</a> (a, b))) -> b -> m [a] <a href="#v:unfoldrM" class="selflink">#</a></p><div class="doc"><p><code><a href="Distribution-Compat-Prelude-Internal.html#v:unfoldr" title="Distribution.Compat.Prelude.Internal">unfoldr</a></code> with monadic action.</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>take 5 $ unfoldrM (\b r -> Just (r + b, b + 1)) (1 :: Int) 2
</code></strong>[3,4,5,6,7]
</pre><p><em>Since: 2.2</em></p></div></div><div class="top"><p class="src"><a id="v:spanMaybe" class="def">spanMaybe</a> :: (a -> <a href="Distribution-Compat-Prelude-Internal.html#t:Maybe" title="Distribution.Compat.Prelude.Internal">Maybe</a> b) -> [a] -> ([b], [a]) <a href="#v:spanMaybe" class="selflink">#</a></p><div class="doc"><p>Like <code><a href="Distribution-Compat-Prelude-Internal.html#v:span" title="Distribution.Compat.Prelude.Internal">span</a></code> but with <code><a href="Distribution-Compat-Prelude-Internal.html#t:Maybe" title="Distribution.Compat.Prelude.Internal">Maybe</a></code> predicate</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>spanMaybe listToMaybe [[1,2],[3],[],[4,5],[6,7]]
</code></strong>([1,3],[[],[4,5],[6,7]])
</pre><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>spanMaybe (readMaybe :: String -> Maybe Int) ["1", "2", "foo"]
</code></strong>([1,2],["foo"])
</pre><p><em>Since: 2.2</em></p></div></div><div class="top"><p class="src"><a id="v:breakMaybe" class="def">breakMaybe</a> :: (a -> <a href="Distribution-Compat-Prelude-Internal.html#t:Maybe" title="Distribution.Compat.Prelude.Internal">Maybe</a> b) -> [a] -> ([a], <a href="Distribution-Compat-Prelude-Internal.html#t:Maybe" title="Distribution.Compat.Prelude.Internal">Maybe</a> (b, [a])) <a href="#v:breakMaybe" class="selflink">#</a></p><div class="doc"><p>Like <code><a href="Distribution-Compat-Prelude-Internal.html#v:break" title="Distribution.Compat.Prelude.Internal">break</a></code>, but with <code><a href="Distribution-Compat-Prelude-Internal.html#t:Maybe" title="Distribution.Compat.Prelude.Internal">Maybe</a></code> predicate</p><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>breakMaybe (readMaybe :: String -> Maybe Int) ["foo", "bar", "1", "2", "quu"]
</code></strong>(["foo","bar"],Just (1,["2","quu"]))
</pre><pre class="screen"><code class="prompt">>>> </code><strong class="userinput"><code>breakMaybe (readMaybe :: String -> Maybe Int) ["foo", "bar"]
</code></strong>(["foo","bar"],Nothing)
</pre><p><em>Since: 2.2</em></p></div></div><a href="#g:8" id="g:8"><h1>FilePath stuff</h1></a><div class="top"><p class="src"><a id="v:isAbsoluteOnAnyPlatform" class="def">isAbsoluteOnAnyPlatform</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:FilePath" title="Distribution.Compat.Prelude.Internal">FilePath</a> -> <a href="Distribution-Compat-Prelude-Internal.html#t:Bool" title="Distribution.Compat.Prelude.Internal">Bool</a> <a href="#v:isAbsoluteOnAnyPlatform" class="selflink">#</a></p><div class="doc"><p><code><a href="Distribution-Utils-Generic.html#v:isAbsoluteOnAnyPlatform" title="Distribution.Utils.Generic">isAbsoluteOnAnyPlatform</a></code> and <code><a href="Distribution-Utils-Generic.html#v:isRelativeOnAnyPlatform" title="Distribution.Utils.Generic">isRelativeOnAnyPlatform</a></code> are like
<code><a href="file:///opt/ghc/8.4.3/share/doc/ghc-8.4.3/html/libraries/filepath-1.4.2/System-FilePath.html#v:isAbsolute" title="System.FilePath">isAbsolute</a></code> and <code><a href="file:///opt/ghc/8.4.3/share/doc/ghc-8.4.3/html/libraries/filepath-1.4.2/System-FilePath.html#v:isRelative" title="System.FilePath">isRelative</a></code> but have
platform independent heuristics.
The System.FilePath exists in two versions, Windows and Posix. The two
versions don't agree on what is a relative path and we don't know if we're
given Windows or Posix paths.
This results in false positives when running on Posix and inspecting
Windows paths, like the hackage server does.
System.FilePath.Posix.isAbsolute "C:\hello" == False
System.FilePath.Windows.isAbsolute "/hello" == False
This means that we would treat paths that start with "/" to be absolute.
On Posix they are indeed absolute, while on Windows they are not.</p><p>The portable versions should be used when we might deal with paths that
are from another OS than the host OS. For example, the Hackage Server
deals with both Windows and Posix paths while performing the
PackageDescription checks. In contrast, when we run 'cabal configure' we
do expect the paths to be correct for our OS and we should not have to use
the platform independent heuristics.</p></div></div><div class="top"><p class="src"><a id="v:isRelativeOnAnyPlatform" class="def">isRelativeOnAnyPlatform</a> :: <a href="Distribution-Compat-Prelude-Internal.html#t:FilePath" title="Distribution.Compat.Prelude.Internal">FilePath</a> -> <a href="Distribution-Compat-Prelude-Internal.html#t:Bool" title="Distribution.Compat.Prelude.Internal">Bool</a> <a href="#v:isRelativeOnAnyPlatform" class="selflink">#</a></p><div class="doc"><pre>isRelativeOnAnyPlatform = not . <code><a href="Distribution-Utils-Generic.html#v:isAbsoluteOnAnyPlatform" title="Distribution.Utils.Generic">isAbsoluteOnAnyPlatform</a></code></pre></div></div></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.20.0</p></div></body></html>