From 831f33468f227c0dc96bd31380236f2c77e70c52 Mon Sep 17 00:00:00 2001 From: Josh Chen Date: Thu, 9 Jul 2020 13:35:39 +0200 Subject: Non-annotated object lambda --- spartan/core/Spartan.thy | 65 +++++++++++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 20 deletions(-) (limited to 'spartan/core') diff --git a/spartan/core/Spartan.thy b/spartan/core/Spartan.thy index ed21934..1ca027f 100644 --- a/spartan/core/Spartan.thy +++ b/spartan/core/Spartan.thy @@ -15,24 +15,37 @@ keywords begin -section \Preamble\ +section \Prelude\ declare [[eta_contract=false]] +setup \ +let + val typ = Simple_Syntax.read_typ + fun mixfix (sy, ps, p) = Mixfix (Input.string sy, ps, p, Position.no_range) +in + Sign.del_syntax (Print_Mode.ASCII, true) + [("_lambda", typ "pttrns \ 'a \ logic", mixfix ("(3fn _./ _)", [0, 3], 3))] + #> Sign.del_syntax Syntax.mode_default + [("_lambda", typ "pttrns \ 'a \ logic", mixfix ("(3\_./ _)", [0, 3], 3))] + #> Sign.add_syntax Syntax.mode_default + [("_lambda", typ "pttrns \ 'a \ logic", mixfix ("(3fn _./ _)", [0, 3], 3))] +end +\ + syntax "_dollar" :: \logic \ logic \ logic\ (infixr "$" 3) translations "a $ b" \ "a (b)" -abbreviation (input) K where "K x \ \_. x" - - -section \Metatype setup\ +abbreviation (input) K where "K x \ fn _. x" typedecl o +judgment has_type :: \o \ o \ prop\ ("(2_:/ _)" 999) -section \Judgments\ -judgment has_type :: \o \ o \ prop\ ("(2_:/ _)" 999) +section \Type annotations\ + +consts anno :: \o \ o \ o\ ("'(_: _')") section \Universes\ @@ -74,15 +87,15 @@ syntax "_lam" :: \idts \ o \ o \ o\ ("(2\_: _./ _)" 30) "_lam2" :: \idts \ o \ o \ o\ translations - "\x xs: A. B" \ "CONST Pi A (\x. _Pi2 xs A B)" - "_Pi2 x A B" \ "\x: A. B" - "\x: A. B" \ "CONST Pi A (\x. B)" - "\x xs: A. b" \ "CONST lam A (\x. _lam2 xs A b)" + "\x xs: A. B" \ "CONST Pi A (fn x. _Pi2 xs A B)" + "_Pi2 x A B" \ "\x: A. B" + "\x: A. B" \ "CONST Pi A (fn x. B)" + "\x xs: A. b" \ "CONST lam A (fn x. _lam2 xs A b)" "_lam2 x A b" \ "\x: A. b" - "\x: A. b" \ "CONST lam A (\x. b)" + "\x: A. b" \ "CONST lam A (fn x. b)" abbreviation Fn (infixr "\" 40) where "A \ B \ \_: A. B" - +term "\x: A. b x" axiomatization where PiF: "\\x. x: A \ B x: U i; A: U i\ \ \x: A. B x: U i" and @@ -113,7 +126,7 @@ axiomatization syntax "_Sum" :: \idt \ o \ o \ o\ ("(2\_: _./ _)" 20) -translations "\x: A. B" \ "CONST Sig A (\x. B)" +translations "\x: A. B" \ "CONST Sig A (fn x. B)" abbreviation Prod (infixl "\" 60) where "A \ B \ \_: A. B" @@ -132,7 +145,7 @@ axiomatization where \x. x : A \ B x: U i; \x y. \x: A; y: B x\ \ f x y: C ; \p. p: \x: A. B x \ C p: U i - \ \ SigInd A (\x. B x) (\p. C p) f p: C p" and + \ \ SigInd A (fn x. B x) (fn p. C p) f p: C p" and Sig_comp: "\ a: A; @@ -140,7 +153,7 @@ axiomatization where \x. x: A \ B x: U i; \p. p: \x: A. B x \ C p: U i; \x y. \x: A; y: B x\ \ f x y: C - \ \ SigInd A (\x. B x) (\p. C p) f \ f a b" and + \ \ SigInd A (fn x. B x) (fn p. C p) f \ f a b" and Sig_cong: "\ \x. x: A \ B x \ B' x; @@ -249,7 +262,7 @@ consts rewrite_HOLE :: "'a::{}" ("\") lemma eta_expand: fixes f :: "'a::{} \ 'b::{}" - shows "f \ \x. f x" . + shows "f \ fn x. f x" . lemma rewr_imp: assumes "PROP A \ PROP B" @@ -301,11 +314,23 @@ text \Automatically insert inhabitation judgments where needed:\ syntax inhabited :: \o \ prop\ ("(_)") translations "inhabited A" \ "CONST has_type {} A" +text \Implicit lambdas\ + +definition lam_i where [implicit]: "lam_i f \ lam ? f" + +syntax + "_lam_i" :: \idts \ o \ o\ ("(2\_./ _)" 30) + "_lam_i2" :: \idts \ o \ o\ +translations + "\x xs. b" \ "CONST lam_i (fn x. _lam_i2 xs b)" + "_lam_i2 x b" \ "\x. b" + "\x. b" \ "CONST lam_i (fn x. b)" + subsection \Lambda coercion\ \ \Coerce object lambdas to meta-lambdas\ abbreviation (input) lambda :: \o \ o \ o\ - where "lambda f \ \x. f `x" + where "lambda f \ fn x. f `x" ML_file \~~/src/Tools/subtyping.ML\ declare [[coercion_enabled, coercion lambda]] @@ -409,8 +434,8 @@ lemma id_U [typechk]: section \Pairs\ -definition "fst A B \ \p: \x: A. B x. SigInd A B (\_. A) (\x y. x) p" -definition "snd A B \ \p: \x: A. B x. SigInd A B (\p. B (fst A B p)) (\x y. y) p" +definition "fst A B \ \p: \x: A. B x. SigInd A B (fn _. A) (fn x y. x) p" +definition "snd A B \ \p: \x: A. B x. SigInd A B (fn p. B (fst A B p)) (fn x y. y) p" lemma fst_type [typechk]: assumes "A: U i" "\x. x: A \ B x: U i" -- cgit v1.2.3