Skip to content

cabal v2-repl scriptfile.hs #6149

Closed
@phadej

Description

@phadej

cabal v2-repl scriptfile.hs outside project to load a scriptfile.hs into repl (GHCi).


Suppose I have a script file like:

{- cabal:
build-depends: base, splitmix
-}

import Data.List (unfoldr)
import Data.Word (Word64)
import System.Random.SplitMix (nextWord64, mkSMGen)

numbers :: [Word64]
numbers = unfoldr (Just . nextWord64) (mkSMGen 42)

main :: IO ()
main = print $ take 10 numbers

cabal v2-run -v0 scriptfile.hs works perfectly, however it takes quite a lot of time, 10s on my machine!

% time cabal v2-run -v0 ExRun.hs
[1275548033995301424,10417309031967933079,2112719111588962399,2726445820918627087,4609004260007739600,11074269206337254866,9733109294540808081,6450629194222476823,8084222243108663947,16253064923614931039]
cabal v2-run -v0 ExRun.hs  10,70s user 1,01s system 99% cpu 11,724 total

Slowness is one issue, after all there's compiling involved. It however makes development of scriptfiles extremely painful.

Yet, if the following worked, the development would be a lot nicer (repl ftw):

% cabal v2-repl ExRun.hs
Resolving dependencies...
Build profile: -w ghc-8.6.5 -O1
In order, the following will be built (use -v for more details):
 - fake-package-0 (exe:script) (first run)
Configuring executable 'script' for fake-package-0..

...

GHCi, version 8.6.5: http://www.haskell.org/ghc/  :? for help
[1 of 1] Compiling Main             ( ExRun.hs, interpreted )
Ok, one module loaded.
*Main> 

*Main> main
[1275548033995301424,10417309031967933079,2112719111588962399,2726445820918627087,4609004260007739600,11074269206337254866,9733109294540808081,6450629194222476823,8084222243108663947,16253064923614931039]

worked, it would be super great.


For now, I try to cabal install --lib the dependencies, and use raw ghci.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions