When I'm working with single file haskell code, without project, I can only dependent on the base package and import it's modules, but when I want to import modules from other packages, I have to create a new project and edit it's package.yaml and add items into dependencies, these works are too heavy for just a single file.
Can I put my mostly used dependencies list into somewhere so that when I load a single file via stack exec -- ghci my-file.hs it will find my imported modules correctly ?
There are a few options:
The --package flag, for ad hoc invocations;
The global project (see also this answer), a default configuration located at ~/.stack/global-project/stack.yaml (or the corresponding path for your OS) which kicks in when working outside of an actual project; and
Stack scripts, which amount to placing a header specifying a Stack invocation atop your source file, as in this example taken from the docs...
#!/usr/bin/env stack
{- stack
script
--resolver lts-6.25
--package turtle
--package "stm async"
--package http-client,http-conduit
-}
... and which are useful when you want something portable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With