Created
March 26, 2019 17:44
-
-
Save gallais/e0e2597fa3393f6b12d7c35361d0d74f to your computer and use it in GitHub Desktop.
Self-contained gist for https://stackoverflow.com/questions/55347900/agda-simplifying-recursive-definitions-involving-thunk
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
open import Size | |
open import Codata.Thunk | |
data BinaryTreePath (i : Size) : Set where | |
here : BinaryTreePath i | |
branchL : Thunk BinaryTreePath i → BinaryTreePath i | |
branchR : Thunk BinaryTreePath i → BinaryTreePath i | |
zero : ∀ {i} → BinaryTreePath i | |
zero = branchL λ where .force → zero | |
infinity : ∀ {i} → BinaryTreePath i | |
infinity = branchR λ where .force → infinity | |
data Choice : Set where | |
L R : Choice | |
choice : ∀ {i} → Choice → Thunk BinaryTreePath i → BinaryTreePath i | |
choice L t = branchL t | |
choice R t = branchR t | |
open import Data.List | |
open import Data.List.NonEmpty | |
_<|_ : ∀ {i} → List Choice → BinaryTreePath i → BinaryTreePath i | |
[] <| t = t | |
(c ∷ cs) <| t = choice c (λ where .force → cs <| t) | |
_⁺<|_ : ∀ {i} → List⁺ Choice → Thunk BinaryTreePath i → BinaryTreePath i | |
(c ∷ cs) ⁺<| t = choice c (λ where .force → cs <| t .force) | |
cycle : ∀ {i} → List⁺ Choice → BinaryTreePath i | |
cycle cs = cs ⁺<| (λ where .force → cycle cs) | |
sqrt2 : ∀ {i} → BinaryTreePath i | |
sqrt2 = cycle (L ∷ R ∷ R ∷ L ∷ []) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment