Questions tagged [runhaskell]

GHC command that allows running a Haskell program as a script, without having to compile it beforehand

runhaskell is a command from the compiler that allows running a Haskell program as a script, without having to compile it beforehand.

Usage

To use it, create and mark executable your Haskell code (that defines main :: IO()), with the line prepended:

#!/usr/bin/env runhaskell

Then, when the script is executed, runhaskell automatically compiles and runs the script. (The runhaskell program strips the shebang line before compiling it).

Pitfalls

  • May not be included with all Haskell implementations
  • The script is compiled, with limited optimization, each time it is run, so performance is slower than a compiled Haskell program
20 questions
56
votes
2 answers

How to make a Haskell cabal project with library+executables that still run with runhaskell/ghci?

If you declare a library + executable sections in a cabal file while avoiding double compilation of the library by putting the library into a hs-source-dirs directory, you cannot usually run your project with ghci and runhaskell anymore, especially…
nh2
  • 24,526
  • 11
  • 79
  • 128
18
votes
1 answer

Difference in getLine functionality with GHCi vs. runhaskell

I've just stumbled upon a thing I don't understand. If I am using GHCi and use getLine I get the following Prelude> a <- getLine Testoo -- the Backspace action results in a '^?' Prelude> a "Test\DELoo" If I write the same in a…
epsilonhalbe
  • 15,637
  • 5
  • 46
  • 74
17
votes
3 answers

How do i use runhaskell with cabal-dev?

Unfortunately cabal-dev ghci does not work in this project, i get an error: Loading package download-0.3.2 ... linking ... ghc: /home/stulli/haskell/ifdl/cabal-dev//lib/download-0.3.2/ghc-7.4.1/HSdownload-0.3.2.o: unknown symbol `stat64' ghc:…
somesoaccount
  • 1,267
  • 15
  • 37
10
votes
1 answer

Difference for ncurses between interpreted and compiled Haskell?

I have a strange problem with functions timeout and getch from the ncurses library used in Haskell. When I use them from GHCi or runhaskell, they work as expected -- getch waits for the number of miliseconds given to timeout and then returns, even…
Jan Špaček
  • 1,111
  • 1
  • 9
  • 24
9
votes
1 answer

How can I unhide ghc library using runhaskell

I'm building simple script with runhaskell and I try to use FastString from ghc-7.10.2. Simply: import FastString main = putStrLn "Hello SO" running it with runhaskell Main.hs results in error: Main.hs:1:8: Could not find module ‘FastString’ …
remdezx
  • 2,939
  • 28
  • 49
8
votes
2 answers

Runhaskell performance anomaly

I'm trying to understand a performance anomaly being observed when running a program under runhaskell. The program in question is: isFactor n = (0 ==) . (mod n) factors x = filter (isFactor x) [2..x] main = putStrLn $ show $ sum $ factors…
Steve
  • 1,555
  • 1
  • 10
  • 15
8
votes
1 answer

How can I load a runhaskell script without a .hs extension with ghci?

I have written a script in haskell named testscript with the following code: #!/usr/bin/env runhaskell main = putStrLn "hello" After making the script executable, I can run it using ./testscript. However, when I try to load the script with ghci…
David Miani
  • 14,518
  • 2
  • 47
  • 66
6
votes
1 answer

Can runhaskell pick up options from .ghci?

Many people include .ghci files in their haskell projects to include needed options to load modules into ghci. Here's an example: :set -isrc -itest -iexamples -packagehspec2 However when trying to run a file containing main through runhaskell one…
shahn
  • 577
  • 2
  • 13
6
votes
1 answer

Error in ghci which I cannot reproduce in written haskell file

I tried to check this stackoverflow answer with ghci and get the following error: > import Data.List > let m = head . sort > m [2,3,4] :5:4: No instance for (Num ()) arising from the literal `2' Possible fix: add an instance…
Stephan Kulla
  • 4,739
  • 3
  • 26
  • 35
3
votes
1 answer

How to specify sandbox directory for runhaskell?

By default, runhaskell seems to ignore shared sandbox paths. When running a haskell file from the command line using runhaskell, how do I set the sandbox directory?
daj
  • 6,962
  • 9
  • 45
  • 79
2
votes
1 answer

Is it possible to pass arguments to `runhaskell` using a Heredoc?

I would like to pass the string "Hello World" to the following Haskell script: main :: IO () main = interact id that sits inside a Heredoc. Is that possible ? I have made a minimal reproducible example (does not currently work): #!/bin/bash echo…
F. Zer
  • 1,081
  • 7
  • 9
1
vote
1 answer

`runhaskell` can't see packages if the arguments are passed in the form of a variable

Whenever I pass explicit parameters to runhaskell command using a variable, in order to make a specific package visible, for example: #!/bin/bash args="'-package pandoc'" runhaskell --ghc-arg="$args"<
F. Zer
  • 1,081
  • 7
  • 9
1
vote
0 answers

runhaskell error attempting to use module `main:Prelude' (.\Prelude.hs) which is not loaded

I am attempting to run a simple Haskell program using runhaskell file.hs. The source code looks like this: main = putStrLn "hello world" The output of runhaskell is an error, which I do not know how to fix: :1:1: error: attempting to…
Andrei Bozantan
  • 3,781
  • 2
  • 30
  • 40
1
vote
0 answers

How to specify execution order of do block when using runhaskell?

Currently I'm trying to learn Haskell IO, and am using System.IO writeFile to edit a text file with this code: main = do putStr "Enter Some Text: " text <- getLine writeFile "text.txt" text putStrLn "Updated!" In ghci this works fine, but when…
E2718
  • 11
  • 3
1
vote
0 answers

Replicating runghc performance with compiled code

I am running an application "as a script" with stack runghc. Naturally, it runs slower that way than when compiled and run with stack exec. I would like to compare the hotspots of the application as run with "runghc" relative to the compiled…
kostmo
  • 6,222
  • 4
  • 40
  • 51
1
2