Why does runghc fail when using -XSafe?

I am trying to run Safe Haskell code with runghc

, but it doesn't seem to work for me.

bgeron@tinker:/tmp/wtf$ ls
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 runghc

; the error is the most confusing. This is mistake?

I am using Ubuntu 14.04 64-bit.


source to share

2 answers

The observed behavior can be explained as follows.

The implementation runghc

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

It issues the following call ghc

, which also shows strange behavior:

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


The ghc implementation in evalatue expression mode will add offensive imports: https://ghc.haskell.org/trac/ghc/browser/ghc/ghc/InteractiveUI.hs#L1154

I'm not sure if this is a bug. I agree to embarrass this.



As mentioned in the comment, just add import System.Environment



All Articles