Source code on Github
------------------------------------------------------------------------
-- Typeclass for types with default values.
------------------------------------------------------------------------

{-# OPTIONS --safe #-}
module Prelude.Default where

open import Prelude.Init; open SetAsType

record Default (A : Type ) : Type  where
  constructor ⌞_⌟
  field def : A
open Default ⦃...⦄ public

private variable A : Type ; B : Type ℓ′

instance
  Default-⊤ : Default 
  Default-⊤ =  tt 

  Default-× :  Default A    Default B   Default (A × B)
  Default-× =  def , def 

  Default-⊎ :  Default A    Default B   Default (A  B)
  Default-⊎ =  inj₁ def 

  Default-Maybe : Default (Maybe A)
  Default-Maybe =  nothing 

  Default-Bool : Default Bool
  Default-Bool =  true 

  Default-ℕ : Default 
  Default-ℕ =  zero 

  Default-ℤ : Default 
  Default-ℤ =  ℤ.pos def 

  Default-Fin :  {n : }  Default (Fin (suc n))
  Default-Fin =  fzero 

  Default-List : Default (List A)
  Default-List =  [] 

  Default-→ :  Default B   Default (A  B)
  Default-→ =  const def