annotate src/coq/Name.v @ 620:d828b143e147

Finish semantics for Featherweight Ur
author Adam Chlipala <adamc@hcoop.net>
date Sat, 21 Feb 2009 14:10:06 -0500
parents
children 75c7a69354d6
rev   line source
adamc@620 1 (* Copyright (c) 2009, Adam Chlipala
adamc@620 2 * All rights reserved.
adamc@620 3 *
adamc@620 4 * Redistribution and use in source and binary forms, with or without
adamc@620 5 * modification, are permitted provided that the following conditions are met:
adamc@620 6 *
adamc@620 7 * - Redistributions of source code must retain the above copyright notice,
adamc@620 8 * this list of conditions and the following disclaimer.
adamc@620 9 * - Redistributions in binary form must reproduce the above copyright notice,
adamc@620 10 * this list of conditions and the following disclaimer in the documentation
adamc@620 11 * and/or other materials provided with the distribution.
adamc@620 12 * - The names of contributors may not be used to endorse or promote products
adamc@620 13 * derived from this software without specific prior written permission.
adamc@620 14 *
adamc@620 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
adamc@620 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
adamc@620 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
adamc@620 18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
adamc@620 19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
adamc@620 20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
adamc@620 21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
adamc@620 22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
adamc@620 23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
adamc@620 24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
adamc@620 25 * POSSIBILITY OF SUCH DAMAGE.
adamc@620 26 *)
adamc@620 27
adamc@620 28 Set Implicit Arguments.
adamc@620 29
adamc@620 30
adamc@620 31 Fixpoint name' (n : nat) : Type :=
adamc@620 32 match n with
adamc@620 33 | O => Empty_set
adamc@620 34 | S n' => option (name' n')
adamc@620 35 end.
adamc@620 36
adamc@620 37 Definition name'_eq_dec : forall n (x y : name' n), {x = y} + {x <> y}.
adamc@620 38 Hint Extern 1 (_ = _ -> False) => congruence.
adamc@620 39
adamc@620 40 induction n; simpl; intuition;
adamc@620 41 repeat match goal with
adamc@620 42 | [ x : Empty_set |- _ ] => destruct x
adamc@620 43 | [ x : option _ |- _ ] => destruct x
adamc@620 44 end; intuition;
adamc@620 45 match goal with
adamc@620 46 | [ IH : _, n1 : name' _, n2 : name' _ |- _ ] =>
adamc@620 47 destruct (IHn n1 n0); subst; intuition
adamc@620 48 end.
adamc@620 49 Qed.
adamc@620 50
adamc@620 51 Definition badName' n (P : name' n -> bool) :
adamc@620 52 {nm : _ | P nm = false} + {forall nm, P nm = true}.
adamc@620 53 Hint Constructors sig.
adamc@620 54 Hint Extern 1 (_ = true) =>
adamc@620 55 match goal with
adamc@620 56 | [ nm : option _ |- _ ] => destruct nm
adamc@620 57 end; auto.
adamc@620 58
adamc@620 59 induction n; simpl; intuition;
adamc@620 60 match goal with
adamc@620 61 | [ IH : forall P : _ -> _,_ |- _ ] =>
adamc@620 62 case_eq (P None);
adamc@620 63 destruct (IH (fun nm => P (Some nm))); firstorder eauto
adamc@620 64 end.
adamc@620 65 Qed.
adamc@620 66
adamc@620 67 Parameter numNames : nat.
adamc@620 68 Definition name := name' (S numNames).
adamc@620 69 Definition name_eq_dec : forall (x y : name), {x = y} + {x <> y} := @name'_eq_dec _.
adamc@620 70 Definition badName : forall P : name -> bool, {nm : _ | P nm = false} + {forall nm, P nm = true} := @badName' _.
adamc@620 71 Definition defaultName : name := None.