Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > 23cb3d2bf665a215618beb14591f5a72 > files > 100

ghc-hlint-devel-1.8.7-1.fc15.i686.rpm

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<!-- Generated by HsColour, http://www.cs.york.ac.uk/fp/darcs/hscolour/ -->
<title>src/Hint/Import.hs</title>
<link type='text/css' rel='stylesheet' href='hscolour.css' />
</head>
<body>
<pre><a name="line-1"></a><span class='hs-comment'>{-# LANGUAGE PatternGuards #-}</span>
<a name="line-2"></a><span class='hs-comment'>{-
<a name="line-3"></a>    Reduce the number of import declarations.
<a name="line-4"></a>    Two import declarations can be combined if:
<a name="line-5"></a>      (note, A[] is A with whatever import list, or none)
<a name="line-6"></a>    
<a name="line-7"></a>    import A[]; import A[] = import A[]
<a name="line-8"></a>    import A(B); import A(C) = import A(B,C)
<a name="line-9"></a>    import A; import A(C) = import A
<a name="line-10"></a>    import A; import A hiding (C) = import A
<a name="line-11"></a>    import A[]; import A[] as Y = import A[] as Y
<a name="line-12"></a>
<a name="line-13"></a>&lt;TEST&gt;
<a name="line-14"></a>import A; import A -- import A
<a name="line-15"></a>import A; import A; import A -- import A
<a name="line-16"></a>import A(Foo) ; import A -- import A
<a name="line-17"></a>import A(Bar(..)); import {-# SOURCE #-} A
<a name="line-18"></a>import A; import B
<a name="line-19"></a>import A(B) ; import A(C) -- import A(B,C)
<a name="line-20"></a>import A; import A hiding (C) -- import A
<a name="line-21"></a>import A; import A as Y -- import A as Y
<a name="line-22"></a>import A; import qualified A as Y
<a name="line-23"></a>import A as B; import A as C
<a name="line-24"></a>import A; import B; import A -- import A
<a name="line-25"></a>import qualified A; import A
<a name="line-26"></a>import B; import A; import A -- import A
<a name="line-27"></a>import A hiding(Foo); import A hiding(Bar)
<a name="line-28"></a>import List -- import Data.List
<a name="line-29"></a>import qualified List -- import qualified Data.List as List
<a name="line-30"></a>import Char(foo) -- import Data.Char(foo)
<a name="line-31"></a>import IO(foo)
<a name="line-32"></a>import IO as X -- import System.IO as X; import System.IO.Error as X; import Control.Exception  as X (bracket,bracket_)
<a name="line-33"></a>&lt;/TEST&gt;
<a name="line-34"></a>-}</span>
<a name="line-35"></a>
<a name="line-36"></a>
<a name="line-37"></a><span class='hs-keyword'>module</span> <span class='hs-conid'>Hint</span><span class='hs-varop'>.</span><span class='hs-conid'>Import</span> <span class='hs-keyword'>where</span>
<a name="line-38"></a>
<a name="line-39"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Hint</span><span class='hs-varop'>.</span><span class='hs-conid'>Type</span>
<a name="line-40"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Util</span>
<a name="line-41"></a><span class='hs-keyword'>import</span> <span class='hs-conid'>Data</span><span class='hs-varop'>.</span><span class='hs-conid'>Maybe</span>
<a name="line-42"></a>
<a name="line-43"></a>
<a name="line-44"></a><a name="importHint"></a><span class='hs-definition'>importHint</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>ModuHint</span>
<a name="line-45"></a><span class='hs-definition'>importHint</span> <span class='hs-keyword'>_</span> <span class='hs-varid'>x</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>concatMap</span> <span class='hs-layout'>(</span><span class='hs-varid'>wrap</span> <span class='hs-varop'>.</span> <span class='hs-varid'>snd</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>groupSortFst</span>
<a name="line-46"></a>                 <span class='hs-keyglyph'>[</span><span class='hs-layout'>(</span><span class='hs-layout'>(</span><span class='hs-varid'>fromNamed</span> <span class='hs-varop'>$</span> <span class='hs-varid'>importModule</span> <span class='hs-varid'>i</span><span class='hs-layout'>,</span><span class='hs-varid'>importPkg</span> <span class='hs-varid'>i</span><span class='hs-layout'>)</span><span class='hs-layout'>,</span><span class='hs-varid'>i</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>i</span> <span class='hs-keyglyph'>&lt;-</span> <span class='hs-varid'>universeBi</span> <span class='hs-varid'>x</span><span class='hs-layout'>,</span> <span class='hs-varid'>not</span> <span class='hs-varop'>$</span> <span class='hs-varid'>importSrc</span> <span class='hs-varid'>i</span><span class='hs-keyglyph'>]</span><span class='hs-layout'>)</span> <span class='hs-varop'>++</span>
<a name="line-47"></a>                 <span class='hs-varid'>concatMap</span> <span class='hs-varid'>hierarchy</span> <span class='hs-layout'>(</span><span class='hs-varid'>universeBi</span> <span class='hs-varid'>x</span><span class='hs-layout'>)</span>
<a name="line-48"></a>
<a name="line-49"></a>
<a name="line-50"></a><a name="wrap"></a><span class='hs-definition'>wrap</span> <span class='hs-keyglyph'>::</span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>ImportDecl</span> <span class='hs-conid'>S</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>Idea</span><span class='hs-keyglyph'>]</span>
<a name="line-51"></a><span class='hs-definition'>wrap</span> <span class='hs-varid'>o</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyglyph'>[</span> <span class='hs-varid'>rawIdea</span> <span class='hs-conid'>Error</span> <span class='hs-str'>"Use fewer imports"</span> <span class='hs-layout'>(</span><span class='hs-varid'>toSrcLoc</span> <span class='hs-varop'>$</span> <span class='hs-varid'>ann</span> <span class='hs-varop'>$</span> <span class='hs-varid'>head</span> <span class='hs-varid'>o</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>f</span> <span class='hs-varid'>o</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>f</span> <span class='hs-varid'>x</span><span class='hs-layout'>)</span>
<a name="line-52"></a>         <span class='hs-keyglyph'>|</span> <span class='hs-conid'>Just</span> <span class='hs-varid'>x</span> <span class='hs-keyglyph'>&lt;-</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>simplify</span> <span class='hs-varid'>o</span><span class='hs-keyglyph'>]</span><span class='hs-keyglyph'>]</span>
<a name="line-53"></a>    <span class='hs-keyword'>where</span> <span class='hs-varid'>f</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>unlines</span> <span class='hs-varop'>.</span> <span class='hs-varid'>map</span> <span class='hs-varid'>prettyPrint</span>
<a name="line-54"></a>
<a name="line-55"></a>
<a name="line-56"></a><a name="simplify"></a><span class='hs-definition'>simplify</span> <span class='hs-keyglyph'>::</span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>ImportDecl</span> <span class='hs-conid'>S</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-conid'>Maybe</span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>ImportDecl</span> <span class='hs-conid'>S</span><span class='hs-keyglyph'>]</span>
<a name="line-57"></a><span class='hs-definition'>simplify</span> <span class='hs-conid'>[]</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Nothing</span>
<a name="line-58"></a><span class='hs-definition'>simplify</span> <span class='hs-layout'>(</span><span class='hs-varid'>x</span><span class='hs-conop'>:</span><span class='hs-varid'>xs</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>case</span> <span class='hs-varid'>simplifyHead</span> <span class='hs-varid'>x</span> <span class='hs-varid'>xs</span> <span class='hs-keyword'>of</span>
<a name="line-59"></a>    <span class='hs-conid'>Nothing</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-varid'>fmap</span> <span class='hs-layout'>(</span><span class='hs-varid'>x</span><span class='hs-conop'>:</span><span class='hs-layout'>)</span> <span class='hs-varop'>$</span> <span class='hs-varid'>simplify</span> <span class='hs-varid'>xs</span>
<a name="line-60"></a>    <span class='hs-conid'>Just</span> <span class='hs-varid'>xs</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-conid'>Just</span> <span class='hs-varop'>$</span> <span class='hs-varid'>fromMaybe</span> <span class='hs-varid'>xs</span> <span class='hs-varop'>$</span> <span class='hs-varid'>simplify</span> <span class='hs-varid'>xs</span>
<a name="line-61"></a>
<a name="line-62"></a>
<a name="line-63"></a><a name="simplifyHead"></a><span class='hs-definition'>simplifyHead</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>ImportDecl</span> <span class='hs-conid'>S</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>ImportDecl</span> <span class='hs-conid'>S</span><span class='hs-keyglyph'>]</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-conid'>Maybe</span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>ImportDecl</span> <span class='hs-conid'>S</span><span class='hs-keyglyph'>]</span>
<a name="line-64"></a><span class='hs-definition'>simplifyHead</span> <span class='hs-varid'>x</span> <span class='hs-conid'>[]</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Nothing</span>
<a name="line-65"></a><span class='hs-definition'>simplifyHead</span> <span class='hs-varid'>x</span> <span class='hs-layout'>(</span><span class='hs-varid'>y</span><span class='hs-conop'>:</span><span class='hs-varid'>ys</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>case</span> <span class='hs-varid'>reduce</span> <span class='hs-varid'>x</span> <span class='hs-varid'>y</span> <span class='hs-keyword'>of</span>
<a name="line-66"></a>    <span class='hs-conid'>Nothing</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-varid'>fmap</span> <span class='hs-layout'>(</span><span class='hs-varid'>y</span><span class='hs-conop'>:</span><span class='hs-layout'>)</span> <span class='hs-varop'>$</span> <span class='hs-varid'>simplifyHead</span> <span class='hs-varid'>x</span> <span class='hs-varid'>ys</span>
<a name="line-67"></a>    <span class='hs-conid'>Just</span> <span class='hs-varid'>xy</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-conid'>Just</span> <span class='hs-varop'>$</span> <span class='hs-varid'>xy</span> <span class='hs-conop'>:</span> <span class='hs-varid'>ys</span>
<a name="line-68"></a>
<a name="line-69"></a>
<a name="line-70"></a><a name="reduce"></a><span class='hs-definition'>reduce</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>ImportDecl</span> <span class='hs-conid'>S</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-conid'>ImportDecl</span> <span class='hs-conid'>S</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-conid'>Maybe</span> <span class='hs-layout'>(</span><span class='hs-conid'>ImportDecl</span> <span class='hs-conid'>S</span><span class='hs-layout'>)</span>
<a name="line-71"></a><span class='hs-definition'>reduce</span> <span class='hs-varid'>x</span> <span class='hs-varid'>y</span> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>qual</span><span class='hs-layout'>,</span> <span class='hs-keyword'>as</span><span class='hs-layout'>,</span> <span class='hs-varid'>specs</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Just</span> <span class='hs-varid'>x</span>
<a name="line-72"></a>           <span class='hs-keyglyph'>|</span> <span class='hs-varid'>qual</span><span class='hs-layout'>,</span> <span class='hs-keyword'>as</span><span class='hs-layout'>,</span> <span class='hs-conid'>Just</span> <span class='hs-layout'>(</span><span class='hs-conid'>ImportSpecList</span> <span class='hs-keyword'>_</span> <span class='hs-conid'>False</span> <span class='hs-varid'>xs</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>&lt;-</span> <span class='hs-varid'>importSpecs</span> <span class='hs-varid'>x</span><span class='hs-layout'>,</span> <span class='hs-conid'>Just</span> <span class='hs-layout'>(</span><span class='hs-conid'>ImportSpecList</span> <span class='hs-keyword'>_</span> <span class='hs-conid'>False</span> <span class='hs-varid'>ys</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>&lt;-</span> <span class='hs-varid'>importSpecs</span> <span class='hs-varid'>y</span> <span class='hs-keyglyph'>=</span>
<a name="line-73"></a>                <span class='hs-conid'>Just</span> <span class='hs-varid'>x</span><span class='hs-layout'>{</span><span class='hs-varid'>importSpecs</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Just</span> <span class='hs-varop'>$</span> <span class='hs-conid'>ImportSpecList</span> <span class='hs-varid'>an</span> <span class='hs-conid'>False</span> <span class='hs-varop'>$</span> <span class='hs-varid'>nub_</span> <span class='hs-varop'>$</span> <span class='hs-varid'>xs</span> <span class='hs-varop'>++</span> <span class='hs-varid'>ys</span><span class='hs-layout'>}</span>
<a name="line-74"></a>           <span class='hs-keyglyph'>|</span> <span class='hs-varid'>qual</span><span class='hs-layout'>,</span> <span class='hs-keyword'>as</span><span class='hs-layout'>,</span> <span class='hs-varid'>isNothing</span> <span class='hs-layout'>(</span><span class='hs-varid'>importSpecs</span> <span class='hs-varid'>x</span><span class='hs-layout'>)</span> <span class='hs-varop'>||</span> <span class='hs-varid'>isNothing</span> <span class='hs-layout'>(</span><span class='hs-varid'>importSpecs</span> <span class='hs-varid'>y</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Just</span> <span class='hs-varid'>x</span><span class='hs-layout'>{</span><span class='hs-varid'>importSpecs</span><span class='hs-keyglyph'>=</span><span class='hs-conid'>Nothing</span><span class='hs-layout'>}</span>
<a name="line-75"></a>           <span class='hs-keyglyph'>|</span> <span class='hs-varid'>not</span> <span class='hs-layout'>(</span><span class='hs-varid'>importQualified</span> <span class='hs-varid'>x</span><span class='hs-layout'>)</span><span class='hs-layout'>,</span> <span class='hs-varid'>qual</span><span class='hs-layout'>,</span> <span class='hs-varid'>specs</span><span class='hs-layout'>,</span> <span class='hs-varid'>length</span> <span class='hs-varid'>ass</span> <span class='hs-varop'>==</span> <span class='hs-num'>1</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Just</span> <span class='hs-varid'>x</span><span class='hs-layout'>{</span><span class='hs-varid'>importAs</span><span class='hs-keyglyph'>=</span><span class='hs-conid'>Just</span> <span class='hs-varop'>$</span> <span class='hs-varid'>head</span> <span class='hs-varid'>ass</span><span class='hs-layout'>}</span>
<a name="line-76"></a>    <span class='hs-keyword'>where</span>
<a name="line-77"></a>        <span class='hs-varid'>qual</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>importQualified</span> <span class='hs-varid'>x</span> <span class='hs-varop'>==</span> <span class='hs-varid'>importQualified</span> <span class='hs-varid'>y</span>
<a name="line-78"></a>        <span class='hs-keyword'>as</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>importAs</span> <span class='hs-varid'>x</span> <span class='hs-varop'>`eqMaybe`</span> <span class='hs-varid'>importAs</span> <span class='hs-varid'>y</span>
<a name="line-79"></a>        <span class='hs-varid'>ass</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>mapMaybe</span> <span class='hs-varid'>importAs</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>x</span><span class='hs-layout'>,</span><span class='hs-varid'>y</span><span class='hs-keyglyph'>]</span>
<a name="line-80"></a>        <span class='hs-varid'>specs</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>importSpecs</span> <span class='hs-varid'>x</span> <span class='hs-varop'>`eqMaybe`</span> <span class='hs-varid'>importSpecs</span> <span class='hs-varid'>y</span>
<a name="line-81"></a>
<a name="line-82"></a><span class='hs-definition'>reduce</span> <span class='hs-keyword'>_</span> <span class='hs-keyword'>_</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>Nothing</span>
<a name="line-83"></a>
<a name="line-84"></a>
<a name="line-85"></a>
<a name="line-86"></a><a name="newNames"></a><span class='hs-definition'>newNames</span> <span class='hs-keyglyph'>=</span> <span class='hs-keyword'>let</span> <span class='hs-layout'>(</span><span class='hs-varop'>*</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>flip</span> <span class='hs-conid'>(,)</span> <span class='hs-keyword'>in</span>
<a name="line-87"></a>    <span class='hs-keyglyph'>[</span><span class='hs-str'>"Control"</span> <span class='hs-varop'>*</span> <span class='hs-str'>"Monad"</span>
<a name="line-88"></a>    <span class='hs-layout'>,</span><span class='hs-str'>"Data"</span> <span class='hs-varop'>*</span> <span class='hs-str'>"Char"</span>
<a name="line-89"></a>    <span class='hs-layout'>,</span><span class='hs-str'>"Data"</span> <span class='hs-varop'>*</span> <span class='hs-str'>"List"</span>
<a name="line-90"></a>    <span class='hs-layout'>,</span><span class='hs-str'>"Data"</span> <span class='hs-varop'>*</span> <span class='hs-str'>"Maybe"</span>
<a name="line-91"></a>    <span class='hs-layout'>,</span><span class='hs-str'>"Data"</span> <span class='hs-varop'>*</span> <span class='hs-str'>"Ratio"</span>
<a name="line-92"></a>    <span class='hs-layout'>,</span><span class='hs-str'>"System"</span> <span class='hs-varop'>*</span> <span class='hs-str'>"Directory"</span>
<a name="line-93"></a>
<a name="line-94"></a>    <span class='hs-comment'>-- Special, see bug #393</span>
<a name="line-95"></a>    <span class='hs-comment'>-- ,"System" * "IO"</span>
<a name="line-96"></a>
<a name="line-97"></a>    <span class='hs-comment'>-- Do not encourage use of old-locale/old-time over haskell98</span>
<a name="line-98"></a>    <span class='hs-comment'>-- ,"System" * "Locale"</span>
<a name="line-99"></a>    <span class='hs-comment'>-- ,"System" * "Time"</span>
<a name="line-100"></a>    <span class='hs-keyglyph'>]</span>
<a name="line-101"></a>
<a name="line-102"></a>
<a name="line-103"></a><a name="hierarchy"></a><span class='hs-definition'>hierarchy</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>ImportDecl</span> <span class='hs-conid'>S</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>Idea</span><span class='hs-keyglyph'>]</span>
<a name="line-104"></a><span class='hs-definition'>hierarchy</span> <span class='hs-varid'>i</span><span class='hs-keyglyph'>@</span><span class='hs-conid'>ImportDecl</span><span class='hs-layout'>{</span><span class='hs-varid'>importModule</span><span class='hs-keyglyph'>=</span><span class='hs-conid'>ModuleName</span> <span class='hs-keyword'>_</span> <span class='hs-varid'>x</span><span class='hs-layout'>,</span><span class='hs-varid'>importPkg</span><span class='hs-keyglyph'>=</span><span class='hs-conid'>Nothing</span><span class='hs-layout'>}</span> <span class='hs-keyglyph'>|</span> <span class='hs-conid'>Just</span> <span class='hs-varid'>y</span> <span class='hs-keyglyph'>&lt;-</span> <span class='hs-varid'>lookup</span> <span class='hs-varid'>x</span> <span class='hs-varid'>newNames</span>
<a name="line-105"></a>    <span class='hs-keyglyph'>=</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>warn</span> <span class='hs-str'>"Use hierarchical imports"</span> <span class='hs-varid'>i</span> <span class='hs-layout'>(</span><span class='hs-varid'>desugarQual</span> <span class='hs-varid'>i</span><span class='hs-layout'>)</span><span class='hs-layout'>{</span><span class='hs-varid'>importModule</span><span class='hs-keyglyph'>=</span><span class='hs-conid'>ModuleName</span> <span class='hs-varid'>an</span> <span class='hs-varop'>$</span> <span class='hs-varid'>y</span> <span class='hs-varop'>++</span> <span class='hs-str'>"."</span> <span class='hs-varop'>++</span> <span class='hs-varid'>x</span><span class='hs-layout'>}</span><span class='hs-keyglyph'>]</span>
<a name="line-106"></a>
<a name="line-107"></a><span class='hs-comment'>-- import IO is equivalent to</span>
<a name="line-108"></a><span class='hs-comment'>-- import System.IO, import System.IO.Error, import Control.Exception(bracket, bracket_)</span>
<a name="line-109"></a><span class='hs-definition'>hierarchy</span> <span class='hs-varid'>i</span><span class='hs-keyglyph'>@</span><span class='hs-conid'>ImportDecl</span><span class='hs-layout'>{</span><span class='hs-varid'>importModule</span><span class='hs-keyglyph'>=</span><span class='hs-conid'>ModuleName</span> <span class='hs-keyword'>_</span> <span class='hs-str'>"IO"</span><span class='hs-layout'>,</span> <span class='hs-varid'>importSpecs</span><span class='hs-keyglyph'>=</span><span class='hs-conid'>Nothing</span><span class='hs-layout'>,</span><span class='hs-varid'>importPkg</span><span class='hs-keyglyph'>=</span><span class='hs-conid'>Nothing</span><span class='hs-layout'>}</span>
<a name="line-110"></a>    <span class='hs-keyglyph'>=</span> <span class='hs-keyglyph'>[</span><span class='hs-varid'>rawIdea</span> <span class='hs-conid'>Warning</span> <span class='hs-str'>"Use hierarchical imports"</span> <span class='hs-layout'>(</span><span class='hs-varid'>toSrcLoc</span> <span class='hs-varop'>$</span> <span class='hs-varid'>ann</span> <span class='hs-varid'>i</span><span class='hs-layout'>)</span> <span class='hs-layout'>(</span><span class='hs-varid'>ltrim</span> <span class='hs-varop'>$</span> <span class='hs-varid'>prettyPrint</span> <span class='hs-varid'>i</span><span class='hs-layout'>)</span> <span class='hs-varop'>$</span>
<a name="line-111"></a>          <span class='hs-varid'>unlines</span> <span class='hs-varop'>$</span> <span class='hs-varid'>map</span> <span class='hs-layout'>(</span><span class='hs-varid'>ltrim</span> <span class='hs-varop'>.</span> <span class='hs-varid'>prettyPrint</span><span class='hs-layout'>)</span>
<a name="line-112"></a>          <span class='hs-keyglyph'>[</span><span class='hs-varid'>f</span> <span class='hs-str'>"System.IO"</span> <span class='hs-conid'>Nothing</span><span class='hs-layout'>,</span> <span class='hs-varid'>f</span> <span class='hs-str'>"System.IO.Error"</span> <span class='hs-conid'>Nothing</span>
<a name="line-113"></a>          <span class='hs-layout'>,</span><span class='hs-varid'>f</span> <span class='hs-str'>"Control.Exception"</span> <span class='hs-varop'>$</span> <span class='hs-conid'>Just</span> <span class='hs-varop'>$</span> <span class='hs-conid'>ImportSpecList</span> <span class='hs-varid'>an</span> <span class='hs-conid'>False</span> <span class='hs-keyglyph'>[</span><span class='hs-conid'>IVar</span> <span class='hs-varid'>an</span> <span class='hs-varop'>$</span> <span class='hs-varid'>toNamed</span> <span class='hs-varid'>x</span> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>x</span> <span class='hs-keyglyph'>&lt;-</span> <span class='hs-keyglyph'>[</span><span class='hs-str'>"bracket"</span><span class='hs-layout'>,</span><span class='hs-str'>"bracket_"</span><span class='hs-keyglyph'>]</span><span class='hs-keyglyph'>]</span><span class='hs-keyglyph'>]</span><span class='hs-keyglyph'>]</span>
<a name="line-114"></a>    <span class='hs-keyword'>where</span> <span class='hs-varid'>f</span> <span class='hs-varid'>a</span> <span class='hs-varid'>b</span> <span class='hs-keyglyph'>=</span> <span class='hs-layout'>(</span><span class='hs-varid'>desugarQual</span> <span class='hs-varid'>i</span><span class='hs-layout'>)</span><span class='hs-layout'>{</span><span class='hs-varid'>importModule</span><span class='hs-keyglyph'>=</span><span class='hs-conid'>ModuleName</span> <span class='hs-varid'>an</span> <span class='hs-varid'>a</span><span class='hs-layout'>,</span> <span class='hs-varid'>importSpecs</span><span class='hs-keyglyph'>=</span><span class='hs-varid'>b</span><span class='hs-layout'>}</span>
<a name="line-115"></a>
<a name="line-116"></a><span class='hs-definition'>hierarchy</span> <span class='hs-keyword'>_</span> <span class='hs-keyglyph'>=</span> <span class='hs-conid'>[]</span>
<a name="line-117"></a>
<a name="line-118"></a>
<a name="line-119"></a><a name="desugarQual"></a><span class='hs-comment'>-- import qualified X ==&gt; import qualified X as X</span>
<a name="line-120"></a><span class='hs-definition'>desugarQual</span> <span class='hs-keyglyph'>::</span> <span class='hs-conid'>ImportDecl</span> <span class='hs-conid'>S</span> <span class='hs-keyglyph'>-&gt;</span> <span class='hs-conid'>ImportDecl</span> <span class='hs-conid'>S</span>
<a name="line-121"></a><span class='hs-definition'>desugarQual</span> <span class='hs-varid'>x</span> <span class='hs-keyglyph'>|</span> <span class='hs-varid'>importQualified</span> <span class='hs-varid'>x</span> <span class='hs-varop'>&amp;&amp;</span> <span class='hs-varid'>isNothing</span> <span class='hs-layout'>(</span><span class='hs-varid'>importAs</span> <span class='hs-varid'>x</span><span class='hs-layout'>)</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>x</span><span class='hs-layout'>{</span><span class='hs-varid'>importAs</span><span class='hs-keyglyph'>=</span><span class='hs-conid'>Just</span> <span class='hs-layout'>(</span><span class='hs-varid'>importModule</span> <span class='hs-varid'>x</span><span class='hs-layout'>)</span><span class='hs-layout'>}</span>
<a name="line-122"></a>              <span class='hs-keyglyph'>|</span> <span class='hs-varid'>otherwise</span> <span class='hs-keyglyph'>=</span> <span class='hs-varid'>x</span>
</pre></body>
</html>