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

« back to all changes in this revision

Viewing changes to test/succeed/Filter.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
 
 
2
 
module Filter where
3
 
 
4
 
data Bool : Set where
5
 
  false : Bool
6
 
  true  : Bool
7
 
 
8
 
infixr 40 _::_
9
 
 
10
 
data List (A : Set) : Set where
11
 
  []   : List A
12
 
  _::_ : A -> List A -> List A
13
 
 
14
 
filter : {A : Set} -> (A -> Bool) -> List A -> List A
15
 
filter p [] = []
16
 
filter p (x :: xs) with p x
17
 
...                | true  = x :: filter p xs
18
 
...                | false = filter p xs
19
 
 
20
 
infix 20 _⊆_
21
 
 
22
 
data _⊆_ {A : Set} : List A -> List A -> Set where
23
 
  stop : [] ⊆ []
24
 
  drop : forall {xs y ys} -> xs ⊆ ys -> xs ⊆ y :: ys
25
 
  keep : forall {x xs ys} -> xs ⊆ ys -> x :: xs ⊆ x :: ys
26
 
 
27
 
subset : {A : Set}(p : A -> Bool)(xs : List A) -> filter p xs ⊆ xs
28
 
subset p [] = stop
29
 
subset p (x :: xs) with p x
30
 
...                | true  = keep (subset p xs)
31
 
...                | false = drop (subset p xs)
32