824 \eqref{permute} and alpha-equivalence being equivariant |
826 \eqref{permute} and alpha-equivalence being equivariant |
825 (see Lemma~\ref{alphaeq}). With these two facts at our disposal, we can show |
827 (see Lemma~\ref{alphaeq}). With these two facts at our disposal, we can show |
826 the following lemma about swapping two atoms in an abstraction. |
828 the following lemma about swapping two atoms in an abstraction. |
827 |
829 |
828 \begin{lem} |
830 \begin{lem} |
829 @{thm[mode=IfThen] Abs_swap1(1)[where bs="as", no_vars]} |
831 If @{thm (prem 1) Abs_swap1(1)[where bs="as", no_vars]} and |
|
832 @{thm (prem 2) Abs_swap1(1)[where bs="as", no_vars]} then |
|
833 @{thm (concl) Abs_swap1(1)[where bs="as", no_vars]} |
830 \end{lem} |
834 \end{lem} |
831 |
835 |
832 \begin{proof} |
836 \begin{proof} |
833 This lemma is straightforward using \eqref{abseqiff} and observing that |
837 This lemma is straightforward using \eqref{abseqiff} and observing that |
834 the assumptions give us @{term "(a \<rightleftharpoons> b) \<bullet> (supp x - as) = (supp x - as)"}. |
838 the assumptions give us @{term "(a \<rightleftharpoons> b) \<bullet> (supp x - as) = (supp x - as)"}. |
835 Moreover @{text supp} and set difference are equivariant (see \cite{HuffmanUrban10}). |
|
836 \end{proof} |
839 \end{proof} |
837 |
840 |
838 \noindent |
841 \noindent |
839 Assuming that @{text "x"} has finite support, this lemma together |
842 Assuming that @{text "x"} has finite support, this lemma together |
840 with \eqref{absperm} allows us to show |
843 with \eqref{absperm} allows us to show |
841 |
844 |
842 \begin{equation}\label{halfone} |
845 \begin{equation}\label{halfone} |
843 @{thm Abs_supports(1)[no_vars]} |
846 @{thm Abs_supports(1)[no_vars]} |
844 \end{equation} |
847 \end{equation}\smallskip |
845 |
848 |
846 \noindent |
849 \noindent |
847 which by Property~\ref{supportsprop} gives us ``one half'' of |
850 which by Property~\ref{supportsprop} gives us ``one half'' of |
848 Theorem~\ref{suppabs}. The ``other half'' is a bit more involved. To establish |
851 Theorem~\ref{suppabs}. The ``other half'' is a bit more involved. To establish |
849 it, we use a trick from \cite{Pitts04} and first define an auxiliary |
852 it, we use a trick from \cite{Pitts04} and first define an auxiliary |
850 function @{text aux}, taking an abstraction as argument: |
853 function @{text aux}, taking an abstraction as argument |
851 @{thm supp_set.simps[THEN eq_reflection, no_vars]}. |
854 |
852 |
855 \[ |
|
856 @{thm supp_set.simps[THEN eq_reflection, no_vars]} |
|
857 \]\smallskip |
|
858 |
|
859 \noindent |
853 Using the second equation in \eqref{equivariance}, we can show that |
860 Using the second equation in \eqref{equivariance}, we can show that |
854 @{text "aux"} is equivariant (since @{term "p \<bullet> (supp x - as) = (supp (p \<bullet> x)) - (p \<bullet> as)"}) |
861 @{text "aux"} is equivariant (since @{term "\<pi> \<bullet> (supp x - as) = (supp (\<pi> \<bullet> x)) - (\<pi> \<bullet> as)"}) |
855 and therefore has empty support. |
862 and therefore has empty support. |
856 This in turn means |
863 This in turn means |
857 |
864 |
858 \begin{center} |
865 \[ |
859 @{term "supp (supp_gen (Abs_set as x)) \<subseteq> supp (Abs_set as x)"} |
866 @{term "supp (supp_set (Abs_set as x)) \<subseteq> supp (Abs_set as x)"} |
860 \end{center} |
867 \]\smallskip |
861 |
868 |
862 \noindent |
869 \noindent |
863 using \eqref{suppfun}. Assuming @{term "supp x - as"} is a finite set, |
870 using fact about function applications in \eqref{supps}. Assuming |
864 we further obtain |
871 @{term "supp x - as"} is a finite set, we further obtain |
865 |
872 |
866 \begin{equation}\label{halftwo} |
873 \begin{equation}\label{halftwo} |
867 @{thm (concl) Abs_supp_subset1(1)[no_vars]} |
874 @{thm (concl) Abs_supp_subset1(1)[no_vars]} |
868 \end{equation} |
875 \end{equation}\smallskip |
869 |
876 |
870 \noindent |
877 \noindent |
871 since for finite sets of atoms, @{text "bs"}, we have |
878 since for every finite sets of atoms, say @{text "bs"}, we have |
872 @{thm (concl) supp_finite_atom_set[where S="bs", no_vars]}. |
879 @{thm (concl) supp_finite_atom_set[where S="bs", no_vars]}. |
873 Finally, taking \eqref{halfone} and \eqref{halftwo} together establishes |
880 Finally, taking \eqref{halfone} and \eqref{halftwo} together establishes |
874 Theorem~\ref{suppabs}. |
881 Theorem~\ref{suppabs}. |
875 |
882 |
876 The method of first considering abstractions of the |
883 The method of first considering abstractions of the form @{term "Abs_set as |
877 form @{term "Abs_set as x"} etc is motivated by the fact that |
884 x"} etc is motivated by the fact that we can conveniently establish at the |
878 we can conveniently establish at the Isabelle/HOL level |
885 Isabelle/HOL level properties about them. It would be extremely laborious |
879 properties about them. It would be |
886 to write custom ML-code that derives automatically such properties for every |
880 laborious to write custom ML-code that derives automatically such properties |
887 term-constructor that binds some atoms. Also the generality of the |
881 for every term-constructor that binds some atoms. Also the generality of |
888 definitions for alpha-equivalence will help us in the next sections. |
882 the definitions for alpha-equivalence will help us in the next sections. |
|
883 *} |
889 *} |
884 |
890 |
885 section {* Specifying General Bindings\label{sec:spec} *} |
891 section {* Specifying General Bindings\label{sec:spec} *} |
886 |
892 |
887 text {* |
893 text {* |
912 \isacommand{where}\\ |
918 \isacommand{where}\\ |
913 \raisebox{2mm}{$\ldots$}\\[-2mm] |
919 \raisebox{2mm}{$\ldots$}\\[-2mm] |
914 \end{tabular}} |
920 \end{tabular}} |
915 \end{cases}$\\ |
921 \end{cases}$\\ |
916 \end{tabular}} |
922 \end{tabular}} |
917 \end{equation} |
923 \end{equation}\smallskip |
918 |
924 |
919 \noindent |
925 \noindent |
920 Every type declaration @{text ty}$^\alpha_{1..n}$ consists of a collection of |
926 Every type declaration @{text ty}$^\alpha_{1..n}$ consists of a collection |
921 term-constructors, each of which comes with a list of labelled |
927 of term-constructors, each of which comes with a list of labelled types that |
922 types that stand for the types of the arguments of the term-constructor. |
928 stand for the types of the arguments of the term-constructor. For example a |
923 For example a term-constructor @{text "C\<^sup>\<alpha>"} might be specified with |
929 term-constructor @{text "C\<^sup>\<alpha>"} might be specified with |
924 |
930 |
925 \begin{center} |
931 \[ |
926 @{text "C\<^sup>\<alpha> label\<^isub>1::ty"}$'_1$ @{text "\<dots> label\<^isub>l::ty"}$'_l\;\;$ @{text "binding_clauses"} |
932 @{text "C\<^sup>\<alpha> label\<^isub>1::ty"}\mbox{$'_1$} @{text "\<dots> label\<^isub>l::ty"}\mbox{$'_l\;\;$} @{text "binding_clauses"} |
927 \end{center} |
933 \]\smallskip |
928 |
934 |
929 \noindent |
935 \noindent |
930 whereby some of the @{text ty}$'_{1..l}$ (or their components) |
936 whereby some of the @{text ty}$'_{1..l}$ (or their components) can be |
931 can be contained |
937 contained in the collection of @{text ty}$^\alpha_{1..n}$ declared in |
932 in the collection of @{text ty}$^\alpha_{1..n}$ declared in |
938 \eqref{scheme}. In this case we will call the corresponding argument a |
933 \eqref{scheme}. |
939 \emph{recursive argument} of @{text "C\<^sup>\<alpha>"}. The types of such |
934 In this case we will call the corresponding argument a |
940 recursive arguments need to satisfy a ``positivity'' restriction, which |
935 \emph{recursive argument} of @{text "C\<^sup>\<alpha>"}. |
941 ensures that the type has a set-theoretic semantics (see |
936 The types of such recursive |
942 \cite{Berghofer99}). The labels annotated on the types are optional. Their |
937 arguments need to satisfy a ``positivity'' |
943 purpose is to be used in the (possibly empty) list of \emph{binding |
938 restriction, which ensures that the type has a set-theoretic semantics |
944 clauses}, which indicate the binders and their scope in a term-constructor. |
939 \cite{Berghofer99}. |
945 They come in three \emph{modes}: |
940 The labels |
946 |
941 annotated on the types are optional. Their purpose is to be used in the |
947 |
942 (possibly empty) list of \emph{binding clauses}, which indicate the binders |
948 \[\mbox{ |
943 and their scope in a term-constructor. They come in three \emph{modes}: |
|
944 % |
|
945 \begin{center} |
|
946 \begin{tabular}{@ {}l@ {}} |
949 \begin{tabular}{@ {}l@ {}} |
947 \isacommand{bind} {\it binders} \isacommand{in} {\it bodies}\;\;\;\, |
950 \isacommand{binds} {\it binders} \isacommand{in} {\it bodies}\\ |
948 \isacommand{bind (set)} {\it binders} \isacommand{in} {\it bodies}\;\;\;\, |
951 \isacommand{binds (set)} {\it binders} \isacommand{in} {\it bodies}\\ |
949 \isacommand{bind (set+)} {\it binders} \isacommand{in} {\it bodies} |
952 \isacommand{binds (set+)} {\it binders} \isacommand{in} {\it bodies} |
950 \end{tabular} |
953 \end{tabular}} |
951 \end{center} |
954 \]\smallskip |
952 % |
955 |
953 \noindent |
956 \noindent |
954 The first mode is for binding lists of atoms (the order of binders matters); |
957 The first mode is for binding lists of atoms (the order of bound atoms |
955 the second is for sets of binders (the order does not matter, but the |
958 matters); the second is for sets of binders (the order does not matter, but |
956 cardinality does) and the last is for sets of binders (with vacuous binders |
959 the cardinality does) and the last is for sets of binders (with vacuous |
957 preserving alpha-equivalence). As indicated, the labels in the ``\isacommand{in}-part'' of a binding |
960 binders preserving alpha-equivalence). As indicated, the labels in the |
958 clause will be called \emph{bodies}; the |
961 ``\isacommand{in}-part'' of a binding clause will be called \emph{bodies}; |
959 ``\isacommand{bind}-part'' will be called \emph{binders}. In contrast to |
962 the ``\isacommand{binds}-part'' will be called \emph{binders}. In contrast to |
960 Ott, we allow multiple labels in binders and bodies. |
963 Ott, we allow multiple labels in binders and bodies. For example we allow |
961 |
|
962 For example we allow |
|
963 binding clauses of the form: |
964 binding clauses of the form: |
964 |
965 |
965 \begin{center} |
966 \[\mbox{ |
966 \begin{tabular}{@ {}ll@ {}} |
967 \begin{tabular}{@ {}ll@ {}} |
967 @{text "Foo\<^isub>1 x::name y::name t::trm s::trm"} & |
968 @{text "Foo\<^isub>1 x::name y::name t::trm s::trm"} & |
968 \isacommand{bind} @{text "x y"} \isacommand{in} @{text "t s"}\\ |
969 \isacommand{binds} @{text "x y"} \isacommand{in} @{text "t s"}\\ |
969 @{text "Foo\<^isub>2 x::name y::name t::trm s::trm"} & |
970 @{text "Foo\<^isub>2 x::name y::name t::trm s::trm"} & |
970 \isacommand{bind} @{text "x y"} \isacommand{in} @{text "t"}, |
971 \isacommand{binds} @{text "x y"} \isacommand{in} @{text "t"}, |
971 \isacommand{bind} @{text "x y"} \isacommand{in} @{text "s"}\\ |
972 \isacommand{binds} @{text "x y"} \isacommand{in} @{text "s"}\\ |
972 \end{tabular} |
973 \end{tabular}} |
973 \end{center} |
974 \]\smallskip |
974 |
975 |
975 \noindent |
976 \noindent |
976 Similarly for the other binding modes. |
977 Similarly for the other binding modes. Interestingly, in case of |
977 Interestingly, in case of \isacommand{bind (set)} |
978 \isacommand{binds (set)} and \isacommand{binds (set+)} the binding clauses |
978 and \isacommand{bind (set+)} the binding clauses above will make a difference to the semantics |
979 above will make a difference to the semantics of the specifications (the |
979 of the specifications (the corresponding alpha-equivalence will differ). We will |
980 corresponding alpha-equivalence will differ). We will show this later with |
980 show this later with an example. |
981 an example. |
981 |
982 |
982 There are also some restrictions we need to impose on our binding clauses in comparison to |
983 |
983 the ones of Ott. The |
984 There are also some restrictions we need to impose on our binding clauses in |
984 main idea behind these restrictions is that we obtain a sensible notion of |
985 comparison to the ones of Ott. The main idea behind these restrictions is |
985 alpha-equivalence where it is ensured that within a given scope an |
986 that we obtain a sensible notion of alpha-equivalence where it is ensured |
986 atom occurrence cannot be both bound and free at the same time. The first |
987 that within a given scope an atom occurrence cannot be both bound and free |
987 restriction is that a body can only occur in |
988 at the same time. The first restriction is that a body can only occur in |
988 \emph{one} binding clause of a term constructor (this ensures that the bound |
989 \emph{one} binding clause of a term constructor (this ensures that the bound |
989 atoms of a body cannot be free at the same time by specifying an |
990 atoms of a body cannot be free at the same time by specifying an alternative |
990 alternative binder for the same body). |
991 binder for the same body). |
991 |
992 |
992 For binders we distinguish between |
993 For binders we distinguish between \emph{shallow} and \emph{deep} binders. |
993 \emph{shallow} and \emph{deep} binders. Shallow binders are just |
994 Shallow binders are just labels. The restriction we need to impose on them |
994 labels. The restriction we need to impose on them is that in case of |
995 is that in case of \isacommand{binds (set)} and \isacommand{binds (set+)} the |
995 \isacommand{bind (set)} and \isacommand{bind (set+)} the labels must either |
996 labels must either refer to atom types or to sets of atom types; in case of |
996 refer to atom types or to sets of atom types; in case of \isacommand{bind} |
997 \isacommand{binds} the labels must refer to atom types or lists of atom |
997 the labels must refer to atom types or lists of atom types. Two examples for |
998 types. Two examples for the use of shallow binders are the specification of |
998 the use of shallow binders are the specification of lambda-terms, where a |
999 lambda-terms, where a single name is bound, and type-schemes, where a finite |
999 single name is bound, and type-schemes, where a finite set of names is |
1000 set of names is bound: |
1000 bound: |
1001 |
1001 |
1002 \[\mbox{ |
1002 \begin{center} |
1003 \begin{tabular}{@ {}c@ {\hspace{5mm}}c@ {}} |
1003 \begin{tabular}{@ {}c@ {\hspace{7mm}}c@ {}} |
|
1004 \begin{tabular}{@ {}l} |
1004 \begin{tabular}{@ {}l} |
1005 \isacommand{nominal\_datatype} @{text lam} $=$\\ |
1005 \isacommand{nominal\_datatype} @{text lam} $=$\\ |
1006 \hspace{2mm}\phantom{$\mid$}~@{text "Var name"}\\ |
1006 \hspace{2mm}\phantom{$\mid$}~@{text "Var name"}\\ |
1007 \hspace{2mm}$\mid$~@{text "App lam lam"}\\ |
1007 \hspace{2mm}$\mid$~@{text "App lam lam"}\\ |
1008 \hspace{2mm}$\mid$~@{text "Lam x::name t::lam"}~~\isacommand{bind} @{text x} \isacommand{in} @{text t}\\ |
1008 \hspace{2mm}$\mid$~@{text "Lam x::name t::lam"}\hspace{3mm}% |
|
1009 \isacommand{binds} @{text x} \isacommand{in} @{text t}\\ |
1009 \end{tabular} & |
1010 \end{tabular} & |
1010 \begin{tabular}{@ {}l@ {}} |
1011 \begin{tabular}{@ {}l@ {}} |
1011 \isacommand{nominal\_datatype}~@{text ty} $=$\\ |
1012 \isacommand{nominal\_datatype}~@{text ty} $=$\\ |
1012 \hspace{5mm}\phantom{$\mid$}~@{text "TVar name"}\\ |
1013 \hspace{5mm}\phantom{$\mid$}~@{text "TVar name"}\\ |
1013 \hspace{5mm}$\mid$~@{text "TFun ty ty"}\\ |
1014 \hspace{5mm}$\mid$~@{text "TFun ty ty"}\\ |
1014 \isacommand{and}~@{text "tsc = All xs::(name fset) T::ty"}~~% |
1015 \isacommand{and}~@{text "tsc = All xs::(name fset) T::ty"}\hspace{3mm}% |
1015 \isacommand{bind (set+)} @{text xs} \isacommand{in} @{text T}\\ |
1016 \isacommand{binds (set+)} @{text xs} \isacommand{in} @{text T}\\ |
1016 \end{tabular} |
1017 \end{tabular} |
1017 \end{tabular} |
1018 \end{tabular}} |
1018 \end{center} |
1019 \]\smallskip |
|
1020 |
1019 |
1021 |
1020 \noindent |
1022 \noindent |
1021 In these specifications @{text "name"} refers to an atom type, and @{text |
1023 In these specifications @{text "name"} refers to an atom type, and @{text |
1022 "fset"} to the type of finite sets. |
1024 "fset"} to the type of finite sets. Note that for @{text lam} it does not |
1023 Note that for @{text lam} it does not matter which binding mode we use. The |
1025 matter which binding mode we use. The reason is that we bind only a single |
1024 reason is that we bind only a single @{text name}. However, having |
1026 @{text name}. However, having \isacommand{binds (set)} or \isacommand{binds} |
1025 \isacommand{bind (set)} or \isacommand{bind} in the second case makes a |
1027 in the second case makes a difference to the semantics of the specification |
1026 difference to the semantics of the specification (which we will define in the next section). |
1028 (which we will define in the next section). |
1027 |
|
1028 |
1029 |
1029 A \emph{deep} binder uses an auxiliary binding function that ``picks'' out |
1030 A \emph{deep} binder uses an auxiliary binding function that ``picks'' out |
1030 the atoms in one argument of the term-constructor, which can be bound in |
1031 the atoms in one argument of the term-constructor, which can be bound in |
1031 other arguments and also in the same argument (we will call such binders |
1032 other arguments and also in the same argument (we will call such binders |
1032 \emph{recursive}, see below). The binding functions are |
1033 \emph{recursive}, see below). The binding functions are |
1033 expected to return either a set of atoms (for \isacommand{bind (set)} and |
1034 expected to return either a set of atoms (for \isacommand{binds (set)} and |
1034 \isacommand{bind (set+)}) or a list of atoms (for \isacommand{bind}). They can |
1035 \isacommand{binds (set+)}) or a list of atoms (for \isacommand{binds}). They need |
1035 be defined by recursion over the corresponding type; the equations |
1036 to be defined by recursion over the corresponding type; the equations |
1036 must be given in the binding function part of the scheme shown in |
1037 must be given in the binding function part of the scheme shown in |
1037 \eqref{scheme}. For example a term-calculus containing @{text "Let"}s with |
1038 \eqref{scheme}. For example a term-calculus containing @{text "Let"}s with |
1038 tuple patterns might be specified as: |
1039 tuple patterns might be specified as: |
1039 % |
1040 |
1040 \begin{equation}\label{letpat} |
1041 \begin{equation}\label{letpat} |
1041 \mbox{% |
1042 \mbox{% |
1042 \begin{tabular}{l} |
1043 \begin{tabular}{l} |
1043 \isacommand{nominal\_datatype} @{text trm} $=$\\ |
1044 \isacommand{nominal\_datatype} @{text trm} $=$\\ |
1044 \hspace{5mm}\phantom{$\mid$}~@{term "Var name"}\\ |
1045 \hspace{5mm}\phantom{$\mid$}~@{term "Var name"}\\ |
1045 \hspace{5mm}$\mid$~@{term "App trm trm"}\\ |
1046 \hspace{5mm}$\mid$~@{term "App trm trm"}\\ |
1046 \hspace{5mm}$\mid$~@{text "Lam x::name t::trm"} |
1047 \hspace{5mm}$\mid$~@{text "Lam x::name t::trm"} |
1047 \;\;\isacommand{bind} @{text x} \isacommand{in} @{text t}\\ |
1048 \;\;\isacommand{binds} @{text x} \isacommand{in} @{text t}\\ |
1048 \hspace{5mm}$\mid$~@{text "Let p::pat trm t::trm"} |
1049 \hspace{5mm}$\mid$~@{text "Let p::pat trm t::trm"} |
1049 \;\;\isacommand{bind} @{text "bn(p)"} \isacommand{in} @{text t}\\ |
1050 \;\;\isacommand{binds} @{text "bn(p)"} \isacommand{in} @{text t}\\ |
1050 \isacommand{and} @{text pat} $=$ |
1051 \isacommand{and} @{text pat} $=$\\ |
1051 @{text PNil} |
1052 \hspace{5mm}\phantom{$\mid$}~@{text PNil}\\ |
1052 $\mid$~@{text "PVar name"} |
1053 \hspace{5mm}$\mid$~@{text "PVar name"}\\ |
1053 $\mid$~@{text "PTup pat pat"}\\ |
1054 \hspace{5mm}$\mid$~@{text "PTup pat pat"}\\ |
1054 \isacommand{binder}~@{text "bn::pat \<Rightarrow> atom list"}\\ |
1055 \isacommand{binder}~@{text "bn::pat \<Rightarrow> atom list"}\\ |
1055 \isacommand{where}~@{text "bn(PNil) = []"}\\ |
1056 \isacommand{where}~@{text "bn(PNil) = []"}\\ |
1056 \hspace{5mm}$\mid$~@{text "bn(PVar x) = [atom x]"}\\ |
1057 \hspace{5mm}$\mid$~@{text "bn(PVar x) = [atom x]"}\\ |
1057 \hspace{5mm}$\mid$~@{text "bn(PTup p\<^isub>1 p\<^isub>2) = bn(p\<^isub>1) @ bn(p\<^isub>2)"}\smallskip\\ |
1058 \hspace{5mm}$\mid$~@{text "bn(PTup p\<^isub>1 p\<^isub>2) = bn(p\<^isub>1) @ bn(p\<^isub>2)"}\smallskip\\ |
1058 \end{tabular}} |
1059 \end{tabular}} |
1059 \end{equation} |
1060 \end{equation}\smallskip |
1060 % |
1061 |
1061 \noindent |
1062 \noindent |
1062 In this specification the function @{text "bn"} determines which atoms of |
1063 In this specification the function @{text "bn"} determines which atoms of |
1063 the pattern @{text p} are bound in the argument @{text "t"}. Note that in the |
1064 the pattern @{text p} are bound in the argument @{text "t"}. Note that in the |
1064 second-last @{text bn}-clause the function @{text "atom"} coerces a name |
1065 second-last @{text bn}-clause the function @{text "atom"} coerces a name |
1065 into the generic atom type of Nominal Isabelle \cite{HuffmanUrban10}. This |
1066 into the generic atom type of Nominal Isabelle \cite{HuffmanUrban10}. This |
1066 allows us to treat binders of different atom type uniformly. |
1067 allows us to treat binders of different atom type uniformly. |
1067 |
1068 |
1068 As said above, for deep binders we allow binding clauses such as |
1069 As said above, for deep binders we allow binding clauses such as |
1069 |
1070 |
1070 \begin{center} |
1071 \[\mbox{ |
1071 \begin{tabular}{ll} |
1072 \begin{tabular}{ll} |
1072 @{text "Bar p::pat t::trm"} & |
1073 @{text "Bar p::pat t::trm"} & |
1073 \isacommand{bind} @{text "bn(p)"} \isacommand{in} @{text "p t"} \\ |
1074 \isacommand{binds} @{text "bn(p)"} \isacommand{in} @{text "p t"} \\ |
1074 \end{tabular} |
1075 \end{tabular}} |
1075 \end{center} |
1076 \]\smallskip |
|
1077 |
1076 |
1078 |
1077 \noindent |
1079 \noindent |
1078 where the argument of the deep binder also occurs in the body. We call such |
1080 where the argument of the deep binder also occurs in the body. We call such |
1079 binders \emph{recursive}. To see the purpose of such recursive binders, |
1081 binders \emph{recursive}. To see the purpose of such recursive binders, |
1080 compare ``plain'' @{text "Let"}s and @{text "Let_rec"}s in the following |
1082 compare ``plain'' @{text "Let"}s and @{text "Let_rec"}s in the following |
1081 specification: |
1083 specification: |
1082 % |
1084 |
1083 \begin{equation}\label{letrecs} |
1085 \begin{equation}\label{letrecs} |
1084 \mbox{% |
1086 \mbox{% |
1085 \begin{tabular}{@ {}l@ {}} |
1087 \begin{tabular}{@ {}l@ {}} |
1086 \isacommand{nominal\_datatype}~@{text "trm ="}~\ldots\\ |
1088 \isacommand{nominal\_datatype}~@{text "trm ="}~\ldots\\ |
1087 \hspace{5mm}$\mid$~@{text "Let as::assn t::trm"} |
1089 \hspace{5mm}$\mid$~@{text "Let as::assn t::trm"} |
1088 \;\;\isacommand{bind} @{text "bn(as)"} \isacommand{in} @{text t}\\ |
1090 \;\;\isacommand{binds} @{text "bn(as)"} \isacommand{in} @{text t}\\ |
1089 \hspace{5mm}$\mid$~@{text "Let_rec as::assn t::trm"} |
1091 \hspace{5mm}$\mid$~@{text "Let_rec as::assn t::trm"} |
1090 \;\;\isacommand{bind} @{text "bn(as)"} \isacommand{in} @{text "as t"}\\ |
1092 \;\;\isacommand{binds} @{text "bn(as)"} \isacommand{in} @{text "as t"}\\ |
1091 \isacommand{and} @{text "assn"} $=$ |
1093 \isacommand{and} @{text "assn"} $=$\\ |
1092 @{text "ANil"} |
1094 \hspace{5mm}\phantom{$\mid$}~@{text "ANil"}\\ |
1093 $\mid$~@{text "ACons name trm assn"}\\ |
1095 \hspace{5mm}$\mid$~@{text "ACons name trm assn"}\\ |
1094 \isacommand{binder} @{text "bn::assn \<Rightarrow> atom list"}\\ |
1096 \isacommand{binder} @{text "bn::assn \<Rightarrow> atom list"}\\ |
1095 \isacommand{where}~@{text "bn(ANil) = []"}\\ |
1097 \isacommand{where}~@{text "bn(ANil) = []"}\\ |
1096 \hspace{5mm}$\mid$~@{text "bn(ACons a t as) = [atom a] @ bn(as)"}\\ |
1098 \hspace{5mm}$\mid$~@{text "bn(ACons a t as) = [atom a] @ bn(as)"}\\ |
1097 \end{tabular}} |
1099 \end{tabular}} |
1098 \end{equation} |
1100 \end{equation}\smallskip |
1099 % |
1101 |
1100 \noindent |
1102 \noindent |
1101 The difference is that with @{text Let} we only want to bind the atoms @{text |
1103 The difference is that with @{text Let} we only want to bind the atoms @{text |
1102 "bn(as)"} in the term @{text t}, but with @{text "Let_rec"} we also want to bind the atoms |
1104 "bn(as)"} in the term @{text t}, but with @{text "Let_rec"} we also want to bind the atoms |
1103 inside the assignment. This difference has consequences for the associated |
1105 inside the assignment. This difference has consequences for the associated |
1104 notions of free-atoms and alpha-equivalence. |
1106 notions of free-atoms and alpha-equivalence. |
1840 %\isacommand{and}~@{text "ckind ="}\\ |
1842 %\isacommand{and}~@{text "ckind ="}\\ |
1841 %\phantom{$|$}~@{text "CKSim ty ty"}\\ |
1843 %\phantom{$|$}~@{text "CKSim ty ty"}\\ |
1842 %\isacommand{and}~@{text "ty ="}\\ |
1844 %\isacommand{and}~@{text "ty ="}\\ |
1843 %\phantom{$|$}~@{text "TVar tvar"}~$|$~@{text "T string"}~$|$~@{text "TApp ty ty"}\\ |
1845 %\phantom{$|$}~@{text "TVar tvar"}~$|$~@{text "T string"}~$|$~@{text "TApp ty ty"}\\ |
1844 %$|$~@{text "TFun string ty_list"}~% |
1846 %$|$~@{text "TFun string ty_list"}~% |
1845 %$|$~@{text "TAll tv::tvar tkind ty::ty"} \isacommand{bind}~@{text "tv"}~\isacommand{in}~@{text ty}\\ |
1847 %$|$~@{text "TAll tv::tvar tkind ty::ty"} \isacommand{binds}~@{text "tv"}~\isacommand{in}~@{text ty}\\ |
1846 %$|$~@{text "TArr ckind ty"}\\ |
1848 %$|$~@{text "TArr ckind ty"}\\ |
1847 %\isacommand{and}~@{text "ty_lst ="}\\ |
1849 %\isacommand{and}~@{text "ty_lst ="}\\ |
1848 %\phantom{$|$}~@{text "TNil"}~$|$~@{text "TCons ty ty_lst"}\\ |
1850 %\phantom{$|$}~@{text "TNil"}~$|$~@{text "TCons ty ty_lst"}\\ |
1849 %\isacommand{and}~@{text "cty ="}\\ |
1851 %\isacommand{and}~@{text "cty ="}\\ |
1850 %\phantom{$|$}~@{text "CVar cvar"}~% |
1852 %\phantom{$|$}~@{text "CVar cvar"}~% |
1851 %$|$~@{text "C string"}~$|$~@{text "CApp cty cty"}~$|$~@{text "CFun string co_lst"}\\ |
1853 %$|$~@{text "C string"}~$|$~@{text "CApp cty cty"}~$|$~@{text "CFun string co_lst"}\\ |
1852 %$|$~@{text "CAll cv::cvar ckind cty::cty"} \isacommand{bind}~@{text "cv"}~\isacommand{in}~@{text cty}\\ |
1854 %$|$~@{text "CAll cv::cvar ckind cty::cty"} \isacommand{binds}~@{text "cv"}~\isacommand{in}~@{text cty}\\ |
1853 %$|$~@{text "CArr ckind cty"}~$|$~@{text "CRefl ty"}~$|$~@{text "CSym cty"}~$|$~@{text "CCirc cty cty"}\\ |
1855 %$|$~@{text "CArr ckind cty"}~$|$~@{text "CRefl ty"}~$|$~@{text "CSym cty"}~$|$~@{text "CCirc cty cty"}\\ |
1854 %$|$~@{text "CAt cty ty"}~$|$~@{text "CLeft cty"}~$|$~@{text "CRight cty"}~$|$~@{text "CSim cty cty"}\\ |
1856 %$|$~@{text "CAt cty ty"}~$|$~@{text "CLeft cty"}~$|$~@{text "CRight cty"}~$|$~@{text "CSim cty cty"}\\ |
1855 %$|$~@{text "CRightc cty"}~$|$~@{text "CLeftc cty"}~$|$~@{text "Coerce cty cty"}\\ |
1857 %$|$~@{text "CRightc cty"}~$|$~@{text "CLeftc cty"}~$|$~@{text "Coerce cty cty"}\\ |
1856 %\isacommand{and}~@{text "co_lst ="}\\ |
1858 %\isacommand{and}~@{text "co_lst ="}\\ |
1857 %\phantom{$|$}@{text "CNil"}~$|$~@{text "CCons cty co_lst"}\\ |
1859 %\phantom{$|$}@{text "CNil"}~$|$~@{text "CCons cty co_lst"}\\ |
1858 %\isacommand{and}~@{text "trm ="}\\ |
1860 %\isacommand{and}~@{text "trm ="}\\ |
1859 %\phantom{$|$}~@{text "Var var"}~$|$~@{text "K string"}\\ |
1861 %\phantom{$|$}~@{text "Var var"}~$|$~@{text "K string"}\\ |
1860 %$|$~@{text "LAM_ty tv::tvar tkind t::trm"} \isacommand{bind}~@{text "tv"}~\isacommand{in}~@{text t}\\ |
1862 %$|$~@{text "LAM_ty tv::tvar tkind t::trm"} \isacommand{binds}~@{text "tv"}~\isacommand{in}~@{text t}\\ |
1861 %$|$~@{text "LAM_cty cv::cvar ckind t::trm"} \isacommand{bind}~@{text "cv"}~\isacommand{in}~@{text t}\\ |
1863 %$|$~@{text "LAM_cty cv::cvar ckind t::trm"} \isacommand{binds}~@{text "cv"}~\isacommand{in}~@{text t}\\ |
1862 %$|$~@{text "App_ty trm ty"}~$|$~@{text "App_cty trm cty"}~$|$~@{text "App trm trm"}\\ |
1864 %$|$~@{text "App_ty trm ty"}~$|$~@{text "App_cty trm cty"}~$|$~@{text "App trm trm"}\\ |
1863 %$|$~@{text "Lam v::var ty t::trm"} \isacommand{bind}~@{text "v"}~\isacommand{in}~@{text t}\\ |
1865 %$|$~@{text "Lam v::var ty t::trm"} \isacommand{binds}~@{text "v"}~\isacommand{in}~@{text t}\\ |
1864 %$|$~@{text "Let x::var ty trm t::trm"} \isacommand{bind}~@{text x}~\isacommand{in}~@{text t}\\ |
1866 %$|$~@{text "Let x::var ty trm t::trm"} \isacommand{binds}~@{text x}~\isacommand{in}~@{text t}\\ |
1865 %$|$~@{text "Case trm assoc_lst"}~$|$~@{text "Cast trm co"}\\ |
1867 %$|$~@{text "Case trm assoc_lst"}~$|$~@{text "Cast trm co"}\\ |
1866 %\isacommand{and}~@{text "assoc_lst ="}\\ |
1868 %\isacommand{and}~@{text "assoc_lst ="}\\ |
1867 %\phantom{$|$}~@{text ANil}~% |
1869 %\phantom{$|$}~@{text ANil}~% |
1868 %$|$~@{text "ACons p::pat t::trm assoc_lst"} \isacommand{bind}~@{text "bv p"}~\isacommand{in}~@{text t}\\ |
1870 %$|$~@{text "ACons p::pat t::trm assoc_lst"} \isacommand{binds}~@{text "bv p"}~\isacommand{in}~@{text t}\\ |
1869 %\isacommand{and}~@{text "pat ="}\\ |
1871 %\isacommand{and}~@{text "pat ="}\\ |
1870 %\phantom{$|$}~@{text "Kpat string tvtk_lst tvck_lst vt_lst"}\\ |
1872 %\phantom{$|$}~@{text "Kpat string tvtk_lst tvck_lst vt_lst"}\\ |
1871 %\isacommand{and}~@{text "vt_lst ="}\\ |
1873 %\isacommand{and}~@{text "vt_lst ="}\\ |
1872 %\phantom{$|$}~@{text VTNil}~$|$~@{text "VTCons var ty vt_lst"}\\ |
1874 %\phantom{$|$}~@{text VTNil}~$|$~@{text "VTCons var ty vt_lst"}\\ |
1873 %\isacommand{and}~@{text "tvtk_lst ="}\\ |
1875 %\isacommand{and}~@{text "tvtk_lst ="}\\ |