`stack run` without compilation - Haskell

Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.

rednaZ

How do I make stack run interpret instead of compiling? Or alternatively, how do I make stack runghc app/Main.hs respect package.yaml?

bradrn

Does stack runghc not already respect package.yaml? I thought any Stack command would do so if run within a Stack project directory.

Georgi Lyubenov // googleson78

what do you mean by "interpret instead of compiling"?

Georgi Lyubenov // googleson78

stack runghc is probably something liike stack exec -- runghc so I'd assume it ignores project config

rednaZ

Georgi Lyubenov // googleson78 said:

what do you mean by "interpret instead of compiling"?

I mean what ghci does as opposed to what ghc does.

rednaZ

bradrn said:

Does stack runghc not already respect package.yaml? I thought any Stack command would do so if run within a Stack project directory.

default-extensions are definitely not considered. I do not know if dependencies are because I do not even get that far in the compilation process thanks to default-extensions not being considered.

bradrn

I’m not sure how this follows… e.g. stack exec -- ghcicertainly respects project config insofar as it lets me use non-base dependencies.

Georgi Lyubenov // googleson78

rednaZ said:

Georgi Lyubenov // googleson78 said:

what do you mean by "interpret instead of compiling"?

I mean what ghci does as opposed to what ghc does.

Which part of what ghci does do you need? Afaiu (although I could be completely wrong, since I haven't read any direct topic on the subject), ghci still compiles code, but in a more specific way, and then gives you interactive access to that code (hence why you can't run anything from a module that doesn't compile, even if the particular thing you want to run is fine).

Torsten Schmits

When you load a Haskell source module into GHCi, it is normally converted to byte-code and run using the interpreter.

Georgi Lyubenov // googleson78

but what does byte-code mean? :sweat_smile:

Georgi Lyubenov // googleson78

unless it's something very specialised and the VM is the interpreter

Georgi Lyubenov // googleson78

but then why can't we load individual functions? :triumph:

Georgi Lyubenov // googleson78

in any case, if you want to run with a ghci style, while also reading your project config, maybe writing something like a .ghci file with just main in it and then running stack ghci might work?

bradrn

Isn’t this pretty much exactly what stack runghc does?