Created
January 26, 2019 04:14
-
-
Save emilyhorsman/08b68708904288d2912ed928e83e6371 to your computer and use it in GitHub Desktop.
This file contains 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
open import Data.Bool | |
open import Relation.Binary.PropositionalEquality renaming (refl to definition-chasing) | |
record List (A : Set) : Set where | |
-- Explicitly coinductive. | |
-- The fields of this record are the destructors of this coinductive type. | |
-- Notice: /No/ cons! | |
coinductive | |
field | |
car : A | |
cdr : List A | |
-- This places ~car~ and ~cdr~ in scope. | |
open List | |
-- Define ~alternate~ by the List destructors with copatterns. | |
alternate : {A : Set} → A → A → List A | |
car (alternate a b) = a | |
cdr (alternate a b) = alternate b a | |
-- Does this actually work? | |
test₀ : car (alternate true false) ≡ true | |
test₀ = definition-chasing | |
test₁ : car (cdr (alternate true false)) ≡ false | |
test₁ = definition-chasing |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment