Re: idea: tool to suggest adding imports

2016-03-19 Thread Evan Laforge
On Sat, Mar 19, 2016 at 8:12 AM, Alexander Berntsen
 wrote:
> On 18/03/16 23:51, Evan Laforge wrote:
>> I did this about 5 or 6 years ago for vim, and I'm so used to it I
>> wouldn't want to live without it.
> Is your plug-in free software? Do you have a link to it? It sounds
> very useful to us vim users.

The catch is that it uses qualified imports, which makes everything
easy.  If you're still interested, it's fix-imports on hackage.  There
are lots of others too, but I haven't tried them.
___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users


Re: idea: tool to suggest adding imports

2016-03-19 Thread Alexander Berntsen
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA512

On 18/03/16 23:51, Evan Laforge wrote:
> I did this about 5 or 6 years ago for vim, and I'm so used to it I 
> wouldn't want to live without it.
Is your plug-in free software? Do you have a link to it? It sounds
very useful to us vim users.

- -- 
Alexander
alexan...@plaimi.net
https://secure.plaimi.net/~alexander
-BEGIN PGP SIGNATURE-
Version: GnuPG v2

iQIcBAEBCgAGBQJW7WxmAAoJENQqWdRUGk8BkvsQAIf+1UyESa5YqdXAgPMt33E0
iyEudGMdh86R8WboYf1HmI4LFYdVikKpA8NSEEnc41PbcEsTp0qUjcQ82mcfR+Lh
zHwuZkPOQmlsTIcnOMerLHi+DjgSZRuEXwurBHp7MEpPxqR8nW2eGSq3s0vc4XDv
gUHhqjZXfRs19XhbzBrDiMjD/UeSWgPljfy9VHE6l4yXtw4QwcfaI/RAnl1SvI+2
POddyKemMKtbNIq9zl7H25PhxYSjC0fdgu6OGByRpOu/SvL4WP7tXNEM0Oo/y+Q8
VL6vCCbCYiyhJWPiHJIwz2RJ5EUw973owLuHtazZwQdaKHARILqcdN5lNBza9wHU
+zISRZ5Qsz5VCk7AQNXmBLssTJJAVqWr1lgHpj675n7uS6WjYdVDzNm3s8pG0m2F
SipjVd7HRWdiA0+Eej/Afbuiltd7NDEeAtIlVsCvFX0annotY6I0ne9ZpoL5JWMi
tos+APpoaSxwyiwYdx7+IoBYg5ZRZYCevg09aLR6ehGv8a14xqgZut+LPBjgZ7aU
3PfNlUNLRz39PcJXLR0GqxV2z8f4KD7EirCFj2IPW/yYQmw44ZcvXe96v19IHkiX
yn08XLab/u1Xop4cBOBh5YgHrrjqhRJ6mATsVXFYOK1o2IsOO2rbv+CnJrcXRZxc
9gFDrfsG0EvjGNkR5VHP
=wtXA
-END PGP SIGNATURE-
___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users


idea: tool to suggest adding imports

2016-03-19 Thread John Williams
I have an idea for a tool I'd like to implement, and I'm looking for advice
on the best way to do it.

Ideally, I want to write an Emacs extension where, if I'm editing Haskell
code and I try to use a symbol that's not defined or imported, it will try
to automatically add an appropriate import for the symbol. If instance, if
I have "import Data.Maybe (isNothing)" in my module, and I try to call
"isJust", the extension would automatically change the import to "import
Data.Maybe (isJust, isNothing)".

The Emacs part is easy, but the Haskell part has me kind of lost. Basically
I want to figure out how to heuristically resolve a name, using an existing
set of imports as hints and constraints. The main heuristic I'd like to
implement is that, if some symbols are imported from a module M, consider
importing additional symbols from M. A more advanced heuristic might
suggest that if a symbol is exported from a module M in a visible package
P, the symbol should be imported from M. Finally, if a symbol is exported
by a module in the Haskell platform, I'd like to suggest adding the
relevant package as a dependency in the .cabal and/or stack.yaml file, and
adding an import for it in the .hs file.

Here are some implementation options I'm considering:

1. Add a ghci command to implement my heuristics directly, since ghc
already understands modules, packages and import statements.
2. Load a modified version of the source file into ghci where imports like
"import M (...)" are replaced with "import M", and parse the error messages
about ambiguous symbols.
3. Write a separate tool that reads Haskell imports and duplicates ghc and
cabal's name resolution mechanisms.
4. Write a tool that reads Haskell imports and suggests imports from a list
of commonly imported symbols, ignoring which packages are actually visible.

Right now the options that look best to me are 2 and 4, because the don't
require me to understand or duplicate big parts of ghc, but if modifying
ghc isn't actually that hard, then maybe 1 is the way to go. Option 3 might
be a good way to go if there are libraries I can use to do the hard work
for me.

Any thoughts?
___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users