getting Core Haskell from GHC API with cross-module inlinings

Roman Beslik beroal at
Thu Jun 17 17:41:33 EDT 2010

The following code compiles "A.hs" with GHC API:
import GHC
import Outputable
import DynFlags ( defaultDynFlags )
libdir = "/usr/lib/ghc-6.12.1"
targetFile = "A.hs"
main = defaultErrorHandler defaultDynFlags $ do
     runGhc (Just libdir) $ do
         dflags <- fmap (\dflags -> dflags {optLevel = 2}) 
         setSessionDynFlags dflags
         c <- compileToCoreSimplified targetFile
         print (showSDoc (ppr c))
A.hs: {{{
import Data.Maybe
main = print (show (maybe False (\_ -> True) (Just False)))
When "A.hs" is compiled with GHC API, output contains a reference to 
'maybe'. When "A.hs" is compiled with "ghc -O2 -ddump-simpl", 'maybe' is 
inlined and simplified. Why do outputs differ?

Best regards,
   Roman Beslik.

More information about the Glasgow-haskell-users mailing list