~ubuntu-branches/ubuntu/wily/agda/wily-proposed

« back to all changes in this revision

Viewing changes to test/features/Tree.agda

  • Committer: Package Import Robot
  • Author(s): Iain Lane
  • Date: 2014-08-05 06:38:12 UTC
  • mfrom: (1.1.6)
  • Revision ID: package-import@ubuntu.com-20140805063812-io8e77niomivhd49
Tags: 2.4.0.2-1
* [6e140ac] Imported Upstream version 2.4.0.2
* [2049fc8] Update Build-Depends to match control
* [93dc4d4] Install the new primitives
* [e48f40f] Fix typo dev→doc

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
{-# OPTIONS --copatterns #-}
2
 
module Tree where
3
 
 
4
 
data Bool : Set where
5
 
  true false : Bool
6
 
 
7
 
record Tree (A : Set) : Set where
8
 
  field 
9
 
    label : A
10
 
    child : Bool -> Tree A
11
 
open Tree
12
 
 
13
 
alternate : {A : Set}(a b : A) -> Tree A
14
 
label (child (alternate a b) false)       = b
15
 
child (child (alternate a b) false) true  = alternate a b
16
 
child (child (alternate a b) false) false = alternate a b
17
 
child {A = A} (alternate a b) true = alternate b a
18
 
label {A = A} (alternate a b)      = a
19
 
 
20
 
{- Delivers an infinite tree
21
 
 
22
 
                 a
23
 
            b        b
24
 
          a   a    a   a
25
 
         b b b b  b b b b 
26
 
               ...
27
 
-}
28
 
 
29
 
infixr 5 _::_
30
 
 
31
 
data List (A : Set) : Set where
32
 
  []   : List A
33
 
  _::_ : A -> List A -> List A
34
 
 
35
 
collect : List Bool -> {A : Set} -> Tree A -> List A
36
 
collect []       t = []
37
 
collect (b :: l) t = label t :: collect l (child t b)
38
 
 
39
 
test : List Bool 
40
 
test = collect (true :: true :: true :: []) (alternate true false)
41
 
 
 
 
b'\\ No newline at end of file'