Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6830453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:37:10+00:00 2026-05-26T22:37:10+00:00

I have written a script in haskell named testscript with the following code: #!/usr/bin/env

  • 0

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 (ie with :l testscript), I get the error

target `testscript' is not a module name or a source file

If I rename testscript to testscript.hs, and try loading with ghci again, I get the error

testscript.hs:1:0:  error: invalid preprocessing directive #!
phase `C pre-processor' failed (exitcode = 1)

If I remove the shebang line it works fine. However it is tedious to have to add a .hs extension to the script, remove the top line, then remove the .hs extension and add the shebang line every time I want to try the script in ghci (which is pretty common everytime I want to make a change to it). Is there an easier way to do this?

I’m using ghc version 7.0.3 under Mac OS X 10.6.8

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T22:37:11+00:00Added an answer on May 26, 2026 at 10:37 pm

    You can use the -x option to tell GHCi (or GHC for that matter) to treat all following files as if they had the specified extension.

    There doesn’t seem to be any way to specify this option from within GHCi (for use with :load), but a workaround you can use if you want this is to create a symlink with a .hs extension and load that.

    Your second problem with the shebang line is caused by the C preprocessor being run on your source file for some reason (my old GHC install on Ubuntu does not do this). You can disable this by using the -XNoCPP option.

    So for your case, this should work from the command line:

    ghci -x hs -XNoCPP testscript
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written the following script to search for a motif(substring) in a protein
I have 3 directories named: /home/user/control4 , /home/user/control8 ,/home/user/control16 I have written a script
I have written simple script: #!/bin/bash find . -name *.m4a | while read filename;
I have written following script in python which works fine: from sys import argv
I have written a PHP script based on a piece of code I've found
I have written the following script below - I am not quite happy with
I have written a script that goes through a bunch of files and snips
I'm using emacs and I have written a script which uses current-buffer. However the
I have written a ruby script which opens up dlink admin page in firefox
I have written a watir script that downloads files. One of the files it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.