CompileAsPattern.agda 900 B

1234567891011121314151617181920212223242526272829
  1. -- {-# OPTIONS -v treeless.opt:20 #-}
  2. -- Andreas, 2019-05-07, #3732: cannot have treeless printout in golden value
  3. -- because it is different for the MAlonzo and JS versions now.
  4. module _ where
  5. open import Common.Prelude
  6. module _ {a} {A : Set a} (_<_ : A → A → Bool) where
  7. merge : List A → List A → List A
  8. merge [] ys = ys
  9. merge xs [] = xs
  10. merge xs@(x ∷ xs₁) ys@(y ∷ ys₁) =
  11. if x < y then (x ∷ merge xs₁ ys) -- Generated treeless code should preserve
  12. else (y ∷ merge xs ys₁) -- xs and ys (and not expand to _∷_).
  13. open import Agda.Builtin.Nat
  14. mapM! : {A : Set} → (A → IO Unit) → List A → IO Unit
  15. mapM! f [] = return unit
  16. mapM! f (x ∷ xs) = f x >>= λ _ → mapM! f xs
  17. xs ys : List Nat
  18. xs = 2 ∷ 3 ∷ 5 ∷ 10 ∷ 20 ∷ []
  19. ys = 0 ∷ 1 ∷ 2 ∷ 8 ∷ 10 ∷ 15 ∷ []
  20. main : IO Unit
  21. main = mapM! printNat (merge _<_ xs ys)