]> matita.cs.unibo.it Git - helm.git/blob - helm/software/matita/contribs/ng_assembly/freescale/option.ma
freescale porting to ng, work in progress
[helm.git] / helm / software / matita / contribs / ng_assembly / freescale / option.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 (* ********************************************************************** *)
16 (*                           Progetto FreeScale                           *)
17 (*                                                                        *)
18 (* Sviluppato da:                                                         *)
19 (*   Cosimo Oliboni, oliboni@cs.unibo.it                                  *)
20 (*                                                                        *)
21 (* Questo materiale fa parte della tesi:                                  *)
22 (*   "Formalizzazione Interattiva dei Microcontroller a 8bit FreeScale"   *)
23 (*                                                                        *)
24 (*                    data ultima modifica 15/11/2007                     *)
25 (* ********************************************************************** *)
26
27 include "freescale/bool.ma".
28
29 (* ****** *)
30 (* OPTION *)
31 (* ****** *)
32
33 ninductive option (A:Type) : Type ≝
34   None : option A
35 | Some : A → option A.
36
37 ndefinition option_ind : ΠA:Type.ΠP:option A → Prop.P (None A) → (Πa:A.P (Some A a)) → Πop:option A.P op ≝
38 λA:Type.λP:option A → Prop.λp:P (None A).λf:Πa:A.P (Some A a).λop:option A.
39  match op with [ None ⇒ p | Some (a:A) ⇒ f a ].
40
41 ndefinition option_rec : ΠA:Type.ΠP:option A → Set.P (None A) → (Πa:A.P (Some A a)) → Πop:option A.P op ≝
42 λA:Type.λP:option A → Set.λp:P (None A).λf:Πa:A.P (Some A a).λop:option A.
43  match op with [ None ⇒ p | Some (a:A) ⇒ f a ].
44
45 ndefinition option_rect : ΠA:Type.ΠP:option A → Type.P (None A) → (Πa:A.P (Some A a)) → Πop:option A.P op ≝
46 λA:Type.λP:option A → Type.λp:P (None A).λf:Πa:A.P (Some A a).λop:option A.
47  match op with [ None ⇒ p | Some (a:A) ⇒ f a ].
48
49 ndefinition eq_option ≝
50 λT.λop1,op2:option T.λf:T → T → bool.
51  match op1 with
52   [ None ⇒ match op2 with [ None ⇒ true | Some _ ⇒ false ]
53   | Some x1 ⇒ match op2 with [ None ⇒ false | Some x2 ⇒ f x1 x2 ]
54   ].
55
56 (* option map = match ... with [ None ⇒ None ? | Some .. ⇒ .. ] *)
57 ndefinition opt_map ≝
58 λT1,T2:Type.λt:option T1.λf:T1 → option T2.
59  match t with [ None ⇒ None ? | Some x ⇒ (f x) ].