Closed
Description
It's folklore that we can encode default implicit values in a DTT with instance
arguments that may be explicitly applied. We should add this construct to the
stdlib (I just have something else to do right now so I'm posting this so that
I don't forget about it).
Comments on the name of the constructor / field are welcome.
module Default where
record WithDefault (A : Set) (a : A) : Set where
constructor give
field value : A
open WithDefault
instance
default : ∀ {A a} → WithDefault A a
default {a = a} = give a
open import Agda.Builtin.Nat
inc : Nat → {{step : WithDefault Nat 1}} → Nat
inc m {{step}} = m + step .value
open import Agda.Builtin.Equality
_ : inc 2 ≡ 3
_ = refl
_ : inc 2 {{step = give 3}} ≡ 5
_ = refl