Last active
July 29, 2019 16:46
Revisions
-
carymrobbins revised this gist
Jul 29, 2019 . 1 changed file with 28 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,6 +6,10 @@ main = do thing 2 thing 3 thing' 1 thing' 2 thing' 3 thing :: Int -> IO () thing n = print $ n + cachedExpr where @@ -15,20 +19,44 @@ thing n = print $ n + cachedExpr putStrLn "computing cachedExpr..." pure 5 thing' :: Int -> IO () thing' n = print $ n + cachedExpr' {-# NOINLINE cachedExpr' #-} cachedExpr' :: Int cachedExpr' = unsafePerformIO $ do putStrLn "computing cachedExpr'..." pure 5 {- % ghc -O0 NoInlineWhere.hs -o noinlinewhere && ./noinlinewhere [1 of 1] Compiling Main ( NoInlineWhere.hs, NoInlineWhere.o ) Linking noinlinewhere ... computing cachedExpr... 6 computing cachedExpr... 7 computing cachedExpr... 8 computing cachedExpr'... 6 7 8 % rm noinlinewhere NoInlineWhere.{hi,o} % ghc -O2 NoInlineWhere.hs -o noinlinewhere && ./noinlinewhere [1 of 1] Compiling Main ( NoInlineWhere.hs, NoInlineWhere.o ) Linking noinlinewhere ... computing cachedExpr... 6 7 8 computing cachedExpr'... 6 7 8 -} -
carymrobbins created this gist
Jul 29, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ import System.IO.Unsafe main :: IO () main = do thing 1 thing 2 thing 3 thing :: Int -> IO () thing n = print $ n + cachedExpr where {-# NOINLINE cachedExpr #-} cachedExpr :: Int cachedExpr = unsafePerformIO $ do putStrLn "computing cachedExpr..." pure 5 {- % ghc -O0 NoInlineWhere.hs -o noinlinewhere && ./noinlinewhere computing cachedExpr... 6 computing cachedExpr... 7 computing cachedExpr... 8 % ghc -O2 NoInlineWhere.hs -o noinlinewhere && ./noinlinewhere computing cachedExpr... 6 7 8 -}