Created
July 22, 2022 20:30
-
-
Save bond15/d09a7584dac09bdc4c2974a63670dee1 to your computer and use it in GitHub Desktop.
Smart coproduct injections
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# OPTIONS --overlapping-instances #-} | |
record _<:_ (sub sup : Set) : Set where | |
field | |
inj : sub → sup | |
open import Function | |
open _<:_{{...}} | |
infixr 10 _+_ | |
data _+_ (A B : Set) : Set where | |
inl : A → A + B | |
inr : B → A + B | |
instance | |
_ : {A : Set} → A <: A | |
_ = record { inj = id } | |
_ : {A B : Set} → A <: (A + B) | |
_ = record { inj = inl } | |
_ : {A B C : Set}{{ _ : A <: B}} → A <: ( C + B) | |
_ = record { inj = inr ∘ inj } | |
open import Data.Bool | |
open import Data.Nat hiding (_+_) | |
open import Data.String | |
_ : Bool + ℕ + String | |
_ = inj 8 | |
_ : Bool + ℕ + String | |
_ = inj true | |
_ : Bool + ℕ + String | |
_ = inj "foo" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Coq