Created
January 6, 2017 00:22
-
-
Save larrytheliquid/932d03525223c4cb68ba40aca328cc93 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
{-# OPTIONS --copatterns #-} | |
module CoList where | |
{- High-level intuition: | |
codata CoList (A : Set) : Set where | |
nil : CoList A | |
cons : A → CoList A → CoList A | |
append : ∀{A} → CoList A → CoList A → CoList A | |
append nil ys = ys | |
append (cons x xs) ys = cons x (append xs ys) | |
Co-pattern translation of code: -} | |
mutual | |
data CoList (A : Set) : Set where | |
nil : CoList A | |
cons : CoCons A → CoList A | |
record CoCons (A : Set) : Set where | |
coinductive | |
field | |
hd : A | |
tl : CoList A | |
open CoCons | |
mutual | |
append : ∀{A} → CoList A → CoList A → CoList A | |
append nil ys = ys | |
append (cons xs) ys = cons (appendCons xs ys) | |
appendCons : ∀{A} → CoCons A → CoList A → CoCons A | |
hd (appendCons xs ys) = hd xs | |
tl (appendCons xs ys) = append (tl xs) ys |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment