Skip to content

Adding ssreflect's Reflects idiom #225

@gallais

Description

@gallais

Following Phil's question on the Agda ML, I realised we could maybe benefit
from having Reflects in the standard library:

data Reflects (P : Set) : Bool  Set where
  yes : (p : P)     Reflects P true
  no  : (¬p : ¬ P)  Reflects P false

Sample properties:

map :  {P Q}  (P  Q)  (Q  P)   {b}  Reflects P b  Reflects Q b
map p⇒q q⇒p (yes p) = yes (p⇒q p)
map p⇒q q⇒p (no ¬p) = no (λ q  ¬p (q⇒p q))

dec-Reflects :  {b P}  Reflects P b  Dec P
dec-Reflects (yes p) = yes p
dec-Reflects (no ¬p) = no ¬p

Typical use-case:

_≤ᵇ_ : Bool
zero ≤ᵇ n = true
suc m ≤ᵇ zero = false
suc m ≤ᵇ suc n = m ≤ᵇ n

s≤s-inj :  {m n}  suc m ≤ suc n  m ≤ n
s≤s-inj (s≤s p) = p

≤?⇔≤ᵇ :  m n  Reflects (m ≤ n) (m ≤ᵇ n)
≤?⇔≤ᵇ zero    n       = yes z≤n
≤?⇔≤ᵇ (suc m) zero    = no (λ ())
≤?⇔≤ᵇ (suc m) (suc n) = map s≤s s≤s-inj (≤?⇔≤ᵇ m n)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions