-
Notifications
You must be signed in to change notification settings - Fork 720
Description
When I start hacking a new program, I often start with a single module, and maybe lazily upgrade to a proper full .cabal
+cabal.project
project when a single module becomes too inconvenient. Or not at all. Also, a single small .hs
file is easier to share/move around, or post on blogposts than a project requiring multiple files.
One common issue with one-module runghc
scripts is that we can't easily associate dependency information with them, as they implicitly reference the global/user-pkg dbs. But in the light of new-build
, it would be quite convenient to have one-module scripts carry a subset of build-info meta-data with them so that cabal could bring the necessary packages into scope for that script before invoking runghc.
Therefore I'd suggest to add support for this workflow to cabal; Here's a simple example of what I envision:
#! /usr/bin/env cabal
{- cabal:
index-state: 2016-09-15T12:00:00Z
with-compiler: ghc-8.0.1
build-depends: base ^>= 4.9
, shelly ^>= 1.6.8
-}
main :: IO ()
main = do
...
One design question is whether such a script should auto-install the required dependencies if they're not already cached (and instead abort, telling the user which command to execute in order to populate the cache).
Another is whether cabal should compile the script into an executable, store that some nix-store-like cache (indexed by a computed hash), and run it.