Sharing.agda 764 B

12345678910111213141516171819202122232425
  1. -- Check if sharing is properly used for evaluation.
  2. -- E.g. (\x -> putStrLn x; putStrLn x) (computeString)
  3. -- should only evaluate computeString once.
  4. -- Doing the evaluation twice should still yield the correct result,
  5. -- but will incur a performance penalty.
  6. -- MAlonzo: seems to use proper sharing for this example with ghc -O,
  7. -- but not with ghc -O0. The sharing for -O0 is not introduced by MAlonzo,
  8. -- but by the cleverness of GHC.
  9. module Sharing where
  10. open import Common.Prelude
  11. open import Common.IO
  12. {-# FOREIGN GHC import qualified Debug.Trace #-}
  13. postulate
  14. primTrace : {b : Set} → String → b → b
  15. {-# COMPILE GHC primTrace = \ _ -> Debug.Trace.trace #-}
  16. main : IO Unit
  17. main = (λ x → putStrLn x ,, putStrLn x ) (primTrace "Eval" "hoi")