atom-haskell-archive / haskell-ghc-mod

haskell-ghc-mod atom package
https://atom.io/packages/haskell-ghc-mod
MIT License
69 stars 20 forks source link

Cache all types upfront #177

Open kostmo opened 8 years ago

kostmo commented 8 years ago

Not sure if this is a crazy idea or feasible.

Can ghc-mod (or something) create an index of all of the types in advance (akin to hasktags) so that if a project becomes un-compilable (e.g. mid-refactoring), one can still find out what the type of a given symbol was at the last time the project was compilable?

Java IDEs like Eclipse or IntelliJ somehow can still provide useful type information even when the project is in a non-compilable state.

lierdakil commented 8 years ago

In case of syntax errors, not much can be done, sadly. However, if source is syntactically correct, but doesn't typecheck, ghc-mod usually can figure out most of the types that are not directly dependent on the part that doesn't typecheck, and even then there's some leeway. It is decidedly not possible to get consistent types though (since source doesn't typecheck).

If you're referring to the case where there's half-written code and you want to query types or something like that, learn to use undefined or typed holes (i.e. _) -- that's mostly what it's for anyway.

Generally speaking, gathering all types is feasible, although that would require changes to ghc-mod. But doing that every time source has changed will incur a sizeable performance penalty, especially on larger projects -- something I believe most users would prefer to avoid.