Skip to content

Instantly share code, notes, and snippets.

@ice1000
Created February 5, 2021 16:46
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ice1000/701749602f1cfcff9c64db125e9f928c to your computer and use it in GitHub Desktop.
Save ice1000/701749602f1cfcff9c64db125e9f928c to your computer and use it in GitHub Desktop.
Implementing a lean example in Agda
{- Lean 4
open list
#eval filter (= 4) [1, 2, 4]
-}
open import Data.Nat renaming (ℕ to Nat; _≟_ to decEqNat)
open import Data.List using (List; []; _∷_)
open import Data.Bool using (true; false)
open import Relation.Nullary
open import Relation.Binary.PropositionalEquality
renaming (_≡_ to _==_)
filter : {A : Set} (P : A -> Set)
{{ p : {a : A} -> Dec (P a) }} -> List A -> List A
filter P {{ p }} [] = []
filter P {{ p }} (x ∷ l) with p {x}
... | true because _ = x ∷ filter P {{p}} l
... | false because _ = filter P {{p}} l
instance
decNat : {a b : Nat} -> Dec (a == b)
decNat {a} {b} = decEqNat a b
example = filter (_== 4) (1 ∷ 2 ∷ 4 ∷ [])
_ = example
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment