~ubuntu-branches/ubuntu/wily/coq-doc/wily

« back to all changes in this revision

Viewing changes to contrib/subtac/test/ListsTest.v

  • Committer: Bazaar Package Importer
  • Author(s): Stéphane Glondu, Stéphane Glondu, Samuel Mimram
  • Date: 2010-01-07 22:50:39 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100107225039-n3cq82589u0qt0s2
Tags: 8.2pl1-1
[ Stéphane Glondu ]
* New upstream release (Closes: #563669)
  - remove patches
* Packaging overhaul:
  - use git, advertise it in Vcs-* fields of debian/control
  - use debhelper 7 and dh with override
  - use source format 3.0 (quilt)
* debian/control:
  - set Maintainer to d-o-m, set Uploaders to Sam and myself
  - add Homepage field
  - bump Standards-Version to 3.8.3
* Register PDF documentation into doc-base
* Add debian/watch
* Update debian/copyright

[ Samuel Mimram ]
* Change coq-doc's description to mention that it provides documentation in
  pdf format, not postscript, closes: #543545.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
(* -*- coq-prog-args: ("-emacs-U" "-debug") -*- *)
 
2
Require Import Coq.Program.Program.
 
3
Require Import List.
 
4
 
 
5
Set Implicit Arguments.
 
6
 
 
7
Section Accessors.
 
8
  Variable A : Set.
 
9
 
 
10
  Program Definition myhd : forall (l : list A | length l <> 0), A :=  
 
11
    fun l =>
 
12
      match l with
 
13
        | nil => !
 
14
        | hd :: tl => hd
 
15
      end.
 
16
 
 
17
  Program Definition mytail (l : list A | length l <> 0) : list A :=
 
18
    match l with
 
19
      | nil => !
 
20
      | hd :: tl => tl
 
21
    end.
 
22
End Accessors.
 
23
 
 
24
Program Definition test_hd : nat := myhd (cons 1 nil).
 
25
 
 
26
(*Eval compute in test_hd*)
 
27
(*Program Definition test_tail : list A := mytail nil.*)
 
28
 
 
29
Section app.
 
30
  Variable A : Set.
 
31
 
 
32
  Program Fixpoint app (l : list A) (l' : list A) { struct l } :
 
33
    { r : list A | length r = length l + length l' } :=
 
34
    match l with
 
35
      | nil => l'
 
36
      | hd :: tl => hd :: (tl ++ l')
 
37
    end 
 
38
    where "x ++ y" := (app x y).
 
39
 
 
40
  Next Obligation.
 
41
    intros.
 
42
    destruct_call app ; program_simpl.
 
43
  Defined.
 
44
  
 
45
  Program Lemma app_id_l : forall l : list A, l = nil ++ l.
 
46
  Proof.
 
47
    simpl ; auto.
 
48
  Qed.
 
49
  
 
50
  Program Lemma app_id_r : forall l : list A, l = l ++ nil.
 
51
  Proof.
 
52
    induction l ; simpl in * ; auto. 
 
53
    rewrite <- IHl ; auto.
 
54
  Qed.
 
55
 
 
56
End app.
 
57
 
 
58
Extraction app.
 
59
 
 
60
Section Nth.
 
61
 
 
62
  Variable A : Set.
 
63
 
 
64
  Program Fixpoint nth (l : list A) (n : nat | n < length l) { struct l } : A := 
 
65
    match n, l with
 
66
      | 0, hd :: _ => hd
 
67
      | S n', _ :: tl => nth tl n'
 
68
      | _, nil => !
 
69
    end.
 
70
 
 
71
  Next Obligation.
 
72
  Proof.
 
73
    simpl in *. auto with arith. 
 
74
  Defined.
 
75
 
 
76
  Next Obligation.
 
77
  Proof.
 
78
    inversion H.
 
79
  Qed.
 
80
 
 
81
  Program Fixpoint nth' (l : list A) (n : nat | n < length l) { struct l } : A := 
 
82
    match l, n with
 
83
      | hd :: _, 0 => hd
 
84
      | _ :: tl, S n' => nth' tl n'
 
85
      | nil, _ => !
 
86
    end.
 
87
  Next Obligation.
 
88
  Proof.
 
89
    simpl in *. auto with arith. 
 
90
  Defined.
 
91
 
 
92
  Next Obligation.
 
93
  Proof.
 
94
    intros.
 
95
    inversion H.
 
96
  Defined.
 
97
 
 
98
End Nth.
 
99