StaticPatternLambda.agda 632 B

123456789101112131415161718192021222324252627282930
  1. module _ where
  2. open import Common.Prelude
  3. case_of_ : {A B : Set} → A → (A → B) → B
  4. case x of f = f x
  5. {-# INLINE case_of_ #-}
  6. patlam : Nat → Nat
  7. patlam zero = zero
  8. patlam (suc n) =
  9. case n of λ
  10. { zero → zero
  11. ; (suc m) → m + patlam n
  12. }
  13. static : {A : Set} → A → A
  14. static x = x
  15. {-# STATIC static #-}
  16. -- The static here will make the compiler get to the pattern lambda in the body of patlam
  17. -- before compiling patlam. If we're not careful this might make the pattern lambda not
  18. -- inline in the body of patlam.
  19. foo : Nat → Nat
  20. foo n = static (patlam (suc n))
  21. main : IO Unit
  22. main = printNat (foo 5)