Skip to content

Instantly share code, notes, and snippets.

@gallais
Last active September 12, 2016 15:57
Show Gist options
  • Save gallais/2d060b8800e84a854ef80b10e45a45f6 to your computer and use it in GitHub Desktop.
Save gallais/2d060b8800e84a854ef80b10e45a45f6 to your computer and use it in GitHub Desktop.
Example of Small IR
module Sums where
open import Data.Nat
open import Data.Fin using (Fin; module Fin)
open import Function
sum : (k : ℕ) (f : Fin k → ℕ) → ℕ
sum zero f = 0
sum (suc k) f = f Fin.zero + sum k (f ∘ Fin.suc)
mutual
data Tm : Set where
`val : ℕ → Tm
`sum : (k : Tm) (f : Fin ⟦ k ⟧ → Tm) → Tm
⟦_⟧ : Tm → ℕ
⟦ `val n ⟧ = n
⟦ `sum t f ⟧ = sum ⟦ t ⟧ (λ x → ⟦ f x ⟧)
mutual
data Tm' : Set where
`val : ℕ → Tm'
`sum : (k : Tm') {k' : ℕ} (⟦k⟧ : ⟦ k ⟧'≡ k') (f : Fin k' → Tm') → Tm'
data ⟦_⟧'≡_ : Tm' → ℕ → Set where
`⟦val⟧ : {n : ℕ} → ⟦ `val n ⟧'≡ n
`⟦sum⟧ : {t : Tm'} {t' : ℕ} (⟦t⟧ : ⟦ t ⟧'≡ t') {f : Fin t' → Tm'} {f' : Fin t' → ℕ}
(⟦f⟧ : ∀ k → ⟦ f k ⟧'≡ f' k) → ⟦ `sum t ⟦t⟧ f ⟧'≡ sum t' f'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment