Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does runghc fail when using -XSafe?

Tags:

haskell

I'm trying to run some Safe Haskell code with runghc, but it doesn't seem to work for me.

bgeron@tinker:/tmp/wtf$ ls
Strange.hs
bgeron@tinker:/tmp/wtf$ cat Strange.hs 
module Strange where

main :: IO ()
main = do
    return ()
bgeron@tinker:/tmp/wtf$ runghc -XSafe Strange

Strange:1:1: Not in scope: `System.Environment.withArgs'
bgeron@tinker:/tmp/wtf$ runghc --version
runghc 7.6.3

I thought this would be a valid use of runghc; the error is most confusing. Is this a bug?

I'm using Ubuntu 14.04, 64-bit.

like image 656
Bram Geron Avatar asked Jun 19 '26 12:06

Bram Geron


1 Answers

The observed behaviour can be explained by the following.

The implementation of runghc is here: https://ghc.haskell.org/trac/ghc/browser/ghc/utils/runghc/runghc.hs

It will make the following call to ghc, which also shows the strange behaviour:

ghc -XSafe -e ':main' Strange.hs

The implementation of ghc in evalatue-expression mode will add the offending import: https://ghc.haskell.org/trac/ghc/browser/ghc/ghc/InteractiveUI.hs#L1154

I am not sure whether it's a bug. I agree it's confusing.

like image 93
d8d0d65b3f7cf42 Avatar answered Jun 22 '26 08:06

d8d0d65b3f7cf42



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!