[Haskell-cafe] ANN: fix-imports-0.1.2

Evan Laforge qdunkan at gmail.com
Tue Jul 12 09:18:04 CEST 2011


On Mon, Jul 11, 2011 at 11:48 PM, Ivan Lazar Miljenovic
<ivan.miljenovic at gmail.com> wrote:
>> A small standalone program to manage the import block of a haskell
>> program. It will try to add import lines for qualified names with no
>> corresponding import, remove unused import lines, and sort the import
>> block according to some heuristic you can define. This only works for
>> qualified imports! Unqualified imports are left untouched.
>>
>> It's most convenient if bound to an editor key.
>
> This sounds interesting; it would be helpful if you could provide an
> example if you could provide an example in the README or description
> of what exactly this program does however.

Sure, well... it's like the paragraph above :)

As an example, I just hack away in haskell normally.  When I've edited
a chunk, and have a feeling a changed the dependencies, I hit ',a' in
vim, and it will remove imports that are no longer used, and add
imports that are now needed.  As a bonus it'll sort and format the
import list.

That way I don't have to figure out if there are new modules needed,
go to the top of the file, sift past the module haddock and find the
right spot in the potentially large import list (and maybe I can't
just ! out to 'sort' for that if some are qualified and some are
unqualified), and type all that repetitive 'import qualified
Blah.Blah.Blah as Blah' stuff.  And I don't have to wait for ghc to
warn me about redundant imports and then go delete them one by one.

In addition to being generally convenient, I've found I'm more willing
to use tiny helper functions like 'Maybe.fromMaybe' instead of just
'maybe x id' since the hassle of possibly adding the new import has
been eliminated.

It's a standalone program so it doesn't have to be vim, but that's
what I use, so that's what I include binding glue for.


I've also got an unrelated simple thing that keeps the currently
edited haskell module in a file so I can type :L in ghci to load the
module currently being edited.  Very convenient, especially when
modules start getting nested.



More information about the Haskell-Cafe mailing list