]> matita.cs.unibo.it Git - helm.git/blob - matita/matita/contribs/lambda_delta/ground_2/list.ma
9a5ac0aeb4c7a45014829839d2e4e23f7d7f4c39
[helm.git] / matita / matita / contribs / lambda_delta / ground_2 / list.ma
1 (**************************************************************************)
2 (*       ___                                                              *)
3 (*      ||M||                                                             *)
4 (*      ||A||       A project by Andrea Asperti                           *)
5 (*      ||T||                                                             *)
6 (*      ||I||       Developers:                                           *)
7 (*      ||T||         The HELM team.                                      *)
8 (*      ||A||         http://helm.cs.unibo.it                             *)
9 (*      \   /                                                             *)
10 (*       \ /        This file is distributed under the terms of the       *)
11 (*        v         GNU General Public License Version 2                  *)
12 (*                                                                        *)
13 (**************************************************************************)
14
15 include "ground_2/arith.ma".
16
17 (* LISTS ********************************************************************)
18
19 inductive list (A:Type[0]) : Type[0] :=
20   | nil : list A
21   | cons: A → list A → list A.
22
23 interpretation "nil (list)" 'Nil = (nil ?).
24
25 interpretation "cons (list)" 'Cons hd tl = (cons ? hd tl).
26
27 let rec all A (R:predicate A) (l:list A) on l ≝
28   match l with
29   [ nil        ⇒ ⊤
30   | cons hd tl ⇒ R hd ∧ all A R tl
31   ].
32
33 inductive list2 (A1,A2:Type[0]) : Type[0] :=
34   | nil2 : list2 A1 A2
35   | cons2: A1 → A2 → list2 A1 A2 → list2 A1 A2.
36
37 interpretation "nil (list of pairs)" 'Nil2 = (nil2 ? ?).
38
39 interpretation "cons (list of pairs)" 'Cons hd1 hd2 tl = (cons2 ? ? hd1 hd2 tl).
40
41 let rec append2 (A1,A2:Type[0]) (l1,l2:list2 A1 A2) on l1 ≝ match l1 with
42 [ nil2           ⇒ l2
43 | cons2 a1 a2 tl ⇒ {a1, a2} @ append2 A1 A2 tl l2
44 ].
45
46 interpretation "append (list of pairs)"
47    'Append l1 l2 = (append2 ? ? l1 l2).
48
49 let rec length2 (A1,A2:Type[0]) (l:list2 A1 A2) on l ≝ match l with
50 [ nil2        ⇒ 0
51 | cons2 _ _ l ⇒ length2 A1 A2 l + 1
52 ].
53
54 interpretation "length (list of pairs)"
55    'card l = (length2 ? ? l).