Skip to content

Instantly share code, notes, and snippets.

@emilyhorsman
Created January 26, 2019 04:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emilyhorsman/08b68708904288d2912ed928e83e6371 to your computer and use it in GitHub Desktop.
Save emilyhorsman/08b68708904288d2912ed928e83e6371 to your computer and use it in GitHub Desktop.
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