: sToStat (u : U ); sToStat check, , someU - but check promises, u : U !
, typecheck, , .
, u1 nothing? , nothing. nothing ? Maybe (El u), , - u , , . , u!
Agda , check, , u , check, u, . , Agda :
check {u = nat} {- ... -}
.
, u :
data U : Set where
nat char : U
. , :
El : U → Set
El nat = ℕ
El char = Char
, check {u = char} (just nat)? sToStat someU (nat 1) Maybe ℕ, El u Char!
. - check u1. - unJust,
check : (u1 : Maybe U) → Maybe (El (unJust u1))
- , u1 - just. nothing, !
, - nothing. , u , - . Maybe ⊤ ( , ⊤ , () Haskell - ).
check return Maybe ℕ Maybe ⊤ ? , !
Maybe-El : Maybe U → Set
Maybe-El nothing = Maybe ⊤
Maybe-El (just u) = Maybe (El u)
, ! check :
check : (u : Maybe U) → Maybe-El u
check (just someU) = sToStat someU (nat 1)
check nothing = nothing
, . Maybe-El , .
Maybe-El₂ : Maybe U → Set
Maybe-El₂ = Maybe ∘ helper
where
helper : Maybe U → Set
helper nothing = ⊤
helper (just u) = El u
, , :
Maybe-El₂ : Maybe U → Set
Maybe-El₂ = Maybe ∘ maybe El ⊤
, Maybe-El Maybe-El₂ , . ∀ x → Maybe-El x ≡ Maybe-El₂ x. . Maybe-El x, , x? , . - x .
Maybe-El₂? : Maybe-El₂ x, () . , :
Maybe-El₂ x ⟶ (Maybe ∘ helper) x ⟶ Maybe (helper x)
, helper x , x. , , Maybe-El. ?
:
discard : {A : Set} → Maybe A → Maybe ⊤
discard _ = nothing
, , typecheck.
discard₂ : Maybe U → Maybe ⊤
discard₂ = discard ∘ check
check Maybe y y, ? , : , check x : Maybe-El x, x, , Maybe-El x Maybe y !
Maybe-El₂ . , Maybe-El₂ x Maybe y, discard₂ typechecks!