-
Notifications
You must be signed in to change notification settings - Fork 843
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
Add command line option to stack script to open it in ghci instead of running it #5354
Comments
As a proof-of-concept, I recently created a cross-platform (Windows, Linux, and Mac) tool that does something similar. You specify a resolver and your package dependencies in a comment at the top of your file, and the tool invokes Stack to either run the file as a script, load the file in GHCi (or Ghcid), or compile the file at the user's option. The intent is to make it easy for casual programmers to use Haskell for one-off tasks without needing to create a full Stack project. You can find it here: http://hackage.haskell.org/package/runhs I wonder if it'd be worthwhile to add such a feature directly to Stack. I would rather see it there instead of as a separate tool. If I were to make a PR to add this feature to Stack, would the Stack maintainers approve (assuming, of course, that the code meets the quality standards)? |
This looks cool, but I think it would make more sense to integrate with the existing |
I agree that two formats would be less than ideal. The problem with Stack's current script implementation is that it hardcodes too much context. As you brought up, it hardcodes #!/usr/bin/env stack
-- stack script --resolver nightly --package text
{-# LANGUAGE OverloadedStrings #-}
import Data.Text.IO as T
main = T.putStrLn "Hey." I feel the goal of any fix should address the root problem and define a single format for front matter of extra-project Haskell files that is cross-platform and cross-interpreter (repl, script, or compiler), so that the same source code could be used in any combination of those contexts. This subsumes Stacks current script implementation, so if it would suite your needs (and if the Stack devs agree) it might even make sense to add this feature and deprecate the current scripts implementation. If that doesn't sound like it'd suite your needs, I'll create a separate issue. |
I suppose by this you are referring to the shebang. I'm pretty sure that even on windows (don't have Windows easily accessible to test though) you can run this using In my opinion replacing the existing functionality with Unless of course |
I guess I was premature in saying "no way." What I meant is that it can't be made executable and then invoked at the command line, but as you pointed out, there's a way around that by invoking Since the primary goal of Stack is reproducible builds, I agree with you that we would not want to see the Stack devs remove the ability to use Stack as a script interpreter. Along those same lines, we wouldn't want them to stop parsing the existing front matter format. I think you're idea, of adding a |
This would be great, I am trying to use Dante with stack scripts and it seems that this is what is missing to get it working: jyp/dante#165 . @lehmacdj do you still plan to make a PR for this? I would love to help or maybe even do it on my own - I am not sure how much work will this be. |
I would probably still be willing to work on this, but I would prefer to have blessing from a contributor to stack before getting started, and agreement on what the design should be. I don’t expect this will be a terribly large amount of work. |
@lehmacdj makes sense! My 2 cents: |
I was just looking at support for stack scripts in haskell-language-server, and it seems they can't implement support for it until Stack adds support for running scripts in ghci (which this issue is about). This is mentioned here: haskell/hie-bios#217 and here haskell/haskell-language-server#111. Also interesting: in the issue above, they say that before Anyway, figuring this out would enable both dante and hls to work with stack scripts. What I am not sure about is if it should be done as |
This issue might be useful for implementing this: #5525 . |
For what its worth, I (a person somewhat new to Haskell) recently asked how to do this on the Haskell subreddit. Eventually I accepted that Stack can't do this (right now) but discovered It looks like a similar request has been given to Cabal. |
I'm aware that this option exists:
but I tend to want to do this while developing a script and at no other time.
It would be useful to have an option
stack script --ghci
so that I can start a script in GHCi from my editor tooling, but still leave the header the same, so that I can run it normally when I execute it.I would be happy to implement this if there is interest, and I can get a little bit of help getting started with this repo if I need it.
The text was updated successfully, but these errors were encountered: