Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type query from up to date file information #185

Closed
dudebout opened this issue Jul 16, 2013 · 21 comments
Closed

Type query from up to date file information #185

dudebout opened this issue Jul 16, 2013 · 21 comments

Comments

@dudebout
Copy link

When I use the function haskell-process-do-type (C-c C-t) I often get the answer "Top level: Not in scope: foo'". This is because the query made byhaskell-modeuses the current content loaded inghci` and not the content of the file.

Is there a reason why the call to haskell-process-do-type does not reload the content of the file in ghci before querying it?

The same question applies to haskell-process-do-info (C-c C-i).

@chrisdone
Copy link
Member

There's no particular reason. It could send an import, or optionally a reload, before doing that. I wouldn't personally have it on by default, but it could be an option.

@dudebout
Copy link
Author

I am curious why you would not have this on by default? For efficiency reason? If so, would a "reload-if-newer" approach be more desirable?

@chrisdone
Copy link
Member

Possibly, yeah. GHCi is a bit finicky.

@hvr
Copy link
Member

hvr commented Jul 16, 2013

Well, here's one reason for not wanting this always: sometimes you're in the middle of editing your code when you want to check the type, and the code wouldn't type-check/parse yet properly...

@dudebout
Copy link
Author

What would then be the expected type returned by such a check?

@hvr
Copy link
Member

hvr commented Jul 16, 2013

Probably the last state during editing for which the code still made sense to the compiler... but we'd need incremental compiler support for this to become practical imho, as you can't trigger a save-buffer + reload in GHCi for each character you type... (+ reverting to previous state if :reload fails)

@dudebout
Copy link
Author

I believe that the query should be in sync with what is shown in the buffer. Anything else is confusing. If I have to keep in mind what state is in ghci it will lead to some confusion.

I would rather see with flycheck that the code does not parse and have C-c C-t fail rather than it returning an incorrect type.

@hvr
Copy link
Member

hvr commented Jul 17, 2013

I believe that the query should be in sync with what is shown in the buffer. Anything else is confusing.

Btw, you're contradicting yourself a little bit here. In the original issue description, you wanted the query to be based on the current file-contents, and now you're arguing for using the current buffer-contents instead...

@dudebout
Copy link
Author

All I am saying is that it should reflect what the programmer sees and not what ghci last saw. Either the content of the buffer or the file is fine. If it is the file, I will have emacs save right before I do the query.

@hvr
Copy link
Member

hvr commented Jul 17, 2013

If it is the file, I will have emacs save right before I do the query.

...if you're prepared to type a C-x C-s before you C-c C-{t,i}, what's keeping you from typing C-c C-l (*) before C-c C-{t,i}? ;-)

(*) which currently saves the buffer as a side-effect w/o asking -- which should be made customizable anyway

PS: don't get me wrong, like @chrisdone, I'm not against this feature, I just don't want it on by default

@chrisdone
Copy link
Member

I got the point. It sounds do-able, but if you know Elisp I can point you where you can start with the inferior process if you want. You'll need some ingredients:

  • Make a variable that stores the last module that was loaded and when.
  • When using one of the load commands, if the module succeeds at loading, put it in the variable with the current time.
  • When running type info, check whether the module is in that variable and whether the modified time of the file is greater than the variable (an edited unsaved file is similar). If it's changed, just queue a :load before-hand.

One risk you have is losing type information—if the current module doesn't type-check—that you would've had otherwise. But that's a trade-off with what GHCi provides.

If you don't know Elisp (learn it!), you can leave this ticket open, perhaps someone will add it. Like @hvr says, it's not saving you many key presses.

@chrisdone
Copy link
Member

One risk you have is losing type information—if the current module doesn't type-check—that you would've had otherwise. But that's a trade-off with what GHCi provides.

Afterthought: I read your update posts and see that you'd prefer no type than a possibly-wrong type. Fair enough.

@dudebout
Copy link
Author

@hvr I will have emacs save means that I will add a hook. I am not going to type it ;-)

@chrisdone thanks for the pointers. My main goal with opening this issue was to figure out if there was any reason for the behavior I observed. I will give it a shot.

What I am trying to do is get a neat functionality from ghc-mod which is M-t. You type it on a line lacking a type binding and it will add it appropriately without having to load or save. Very handy!

@chrisdone
Copy link
Member

Check out haskell-process-queue-command and the functions for loading and getting types. The commands sent to the process work in an asynchronous (commands don't block) queue, and are run one-by-one in sequence. Feel free to ask any questions in here.

Getting type info a la ghc-mod will be difficult because GHCi gives very limited inspection capabilities.

@dudebout
Copy link
Author

So far I seemed to get the same result with haskell-mode and ghc-mod. Do you have any example in mind where ghc-mod would give an answer but not ghci?

@chrisdone
Copy link
Member

Sub-expressions? When the file's invalid?

@hvr
Copy link
Member

hvr commented Jul 17, 2013

@chrisdone are you sure ghc-mod type is able to work on invalid Haskell source files?

@dudebout
Copy link
Author

@hvr I just checked. You cannot.

@gracjan
Copy link
Contributor

gracjan commented Mar 1, 2015

This issue report was last update in 2013. Is it still relevant to current code state?

@chrisdone
Copy link
Member

hvr commented on 17 Jul 2013

Sub-expressions? When the file's invalid?
@chrisdone are you sure ghc-mod type is able to work on invalid Haskell source files?

I meant the reverse. GHCi gives you (old) info when the file is invalid. I think ghc-mod does not because it requests type info on-demand.

gracjan commented an hour ago

This issue report was last update in 2013. Is it still relevant to current code state?

Yup.

@gracjan
Copy link
Contributor

gracjan commented Feb 22, 2016

It seems that HIE will provide this functionality. I do not see this happening in haskell-mode due to lack of resources.

@gracjan gracjan closed this as completed Feb 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants