Skip to content

Instantly share code, notes, and snippets.

@gallais
Created May 9, 2017 09:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gallais/95c699fdebf60cb23b1f324f6996047c to your computer and use it in GitHub Desktop.
Save gallais/95c699fdebf60cb23b1f324f6996047c to your computer and use it in GitHub Desktop.
Default named arguments
record Default {ℓ} (A : Set ℓ) (a : A) : Set ℓ where
constructor _!
field value : A
instance
default : ∀ {ℓ} {A : Set ℓ} a → Default A a
default a = record { value = a }
open import Agda.Builtin.Nat
incr : Nat → {{steps : Default Nat 1}} → Nat
incr n {{steps}} = Default.value steps + n
open import Relation.Binary.PropositionalEquality
_ : incr 3 ≡ 4
_ = refl
_ : incr 3 {{steps = 2 !}} ≡ 5
_ = refl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment