src/CCL/Term.thy
changeset 74443 dbf68dbacaff
parent 74441 7fada501211b
child 74444 30995552ea4c
equal deleted inserted replaced
74442:f5c5006d142e 74443:dbf68dbacaff
    44 
    44 
    45 definition ncase :: "[i,i,i\<Rightarrow>i]\<Rightarrow>i"
    45 definition ncase :: "[i,i,i\<Rightarrow>i]\<Rightarrow>i"
    46   where "ncase(n,b,c) == when(n, \<lambda>x. b, \<lambda>y. c(y))"
    46   where "ncase(n,b,c) == when(n, \<lambda>x. b, \<lambda>y. c(y))"
    47 
    47 
    48 
    48 
    49 no_syntax
    49 definition "let1" :: "[i,i\<Rightarrow>i]\<Rightarrow>i"
    50   "_Let" :: "[letbinds, 'a] => 'a"  ("(let (_)/ in (_))" 10)
    50   where let_def: "let1(t, f) == case(t,f(true),f(false), \<lambda>x y. f(<x,y>), \<lambda>u. f(lam x. u(x)))"
    51 
    51 
    52 definition "let" :: "[i,i\<Rightarrow>i]\<Rightarrow>i"
    52 syntax "_let1" :: "[idt,i,i]\<Rightarrow>i"  ("(3let _ be _/ in _)" [0,0,60] 60)
    53   where "let(t, f) == case(t,f(true),f(false), \<lambda>x y. f(<x,y>), \<lambda>u. f(lam x. u(x)))"
    53 translations "let x be a in e" == "CONST let1(a, \<lambda>x. e)"
    54 
       
    55 syntax
       
    56   "_Let" :: "[letbinds, 'a] => 'a"  ("(let (_)/ in (_))" 10)
       
    57 
    54 
    58 definition letrec :: "[[i,i\<Rightarrow>i]\<Rightarrow>i,(i\<Rightarrow>i)\<Rightarrow>i]\<Rightarrow>i"
    55 definition letrec :: "[[i,i\<Rightarrow>i]\<Rightarrow>i,(i\<Rightarrow>i)\<Rightarrow>i]\<Rightarrow>i"
    59   where "letrec(h, b) == b(\<lambda>x. fix(\<lambda>f. lam x. h(x,\<lambda>y. f`y))`x)"
    56   where "letrec(h, b) == b(\<lambda>x. fix(\<lambda>f. lam x. h(x,\<lambda>y. f`y))`x)"
    60 
    57 
    61 definition letrec2 :: "[[i,i,i\<Rightarrow>i\<Rightarrow>i]\<Rightarrow>i,(i\<Rightarrow>i\<Rightarrow>i)\<Rightarrow>i]\<Rightarrow>i"
    58 definition letrec2 :: "[[i,i,i\<Rightarrow>i\<Rightarrow>i]\<Rightarrow>i,(i\<Rightarrow>i\<Rightarrow>i)\<Rightarrow>i]\<Rightarrow>i"
    66   where "letrec3 (h, f) ==
    63   where "letrec3 (h, f) ==
    67     letrec (\<lambda>p g'. split(p,\<lambda>x xs. split(xs,\<lambda>y z. h(x,y,z,\<lambda>u v w. g'(<u,<v,w>>)))),
    64     letrec (\<lambda>p g'. split(p,\<lambda>x xs. split(xs,\<lambda>y z. h(x,y,z,\<lambda>u v w. g'(<u,<v,w>>)))),
    68       \<lambda>g'. f(\<lambda>x y z. g'(<x,<y,z>>)))"
    65       \<lambda>g'. f(\<lambda>x y z. g'(<x,<y,z>>)))"
    69 
    66 
    70 syntax
    67 syntax
    71   "_let" :: "[id,i,i]\<Rightarrow>i"  ("(3let _ be _/ in _)" [0,0,60] 60)
       
    72   "_letrec" :: "[id,id,i,i]\<Rightarrow>i"  ("(3letrec _ _ be _/ in _)" [0,0,0,60] 60)
    68   "_letrec" :: "[id,id,i,i]\<Rightarrow>i"  ("(3letrec _ _ be _/ in _)" [0,0,0,60] 60)
    73   "_letrec2" :: "[id,id,id,i,i]\<Rightarrow>i"  ("(3letrec _ _ _ be _/ in _)" [0,0,0,0,60] 60)
    69   "_letrec2" :: "[id,id,id,i,i]\<Rightarrow>i"  ("(3letrec _ _ _ be _/ in _)" [0,0,0,0,60] 60)
    74   "_letrec3" :: "[id,id,id,id,i,i]\<Rightarrow>i"  ("(3letrec _ _ _ _ be _/ in _)" [0,0,0,0,0,60] 60)
    70   "_letrec3" :: "[id,id,id,id,i,i]\<Rightarrow>i"  ("(3letrec _ _ _ _ be _/ in _)" [0,0,0,0,0,60] 60)
    75 
    71 
    76 ML \<open>
    72 ML \<open>
    77 (** Quantifier translations: variable binding **)
    73 (** Quantifier translations: variable binding **)
    78 
    74 
    79 (* FIXME does not handle "_idtdummy" *)
    75 (* FIXME does not handle "_idtdummy" *)
    80 (* FIXME should use Syntax_Trans.mark_bound, Syntax_Trans.variant_abs' *)
    76 (* FIXME should use Syntax_Trans.mark_bound, Syntax_Trans.variant_abs' *)
    81 
       
    82 fun let_tr [Free x, a, b] = Syntax.const \<^const_syntax>\<open>let\<close> $ a $ absfree x b;
       
    83 fun let_tr' [a,Abs(id,T,b)] =
       
    84   let val (id',b') = Syntax_Trans.variant_abs(id,T,b)
       
    85   in Syntax.const \<^syntax_const>\<open>_let\<close> $ Free(id',T) $ a $ b' end;
       
    86 
    77 
    87 fun letrec_tr [Free f, Free x, a, b] =
    78 fun letrec_tr [Free f, Free x, a, b] =
    88   Syntax.const \<^const_syntax>\<open>letrec\<close> $ absfree x (absfree f a) $ absfree f b;
    79   Syntax.const \<^const_syntax>\<open>letrec\<close> $ absfree x (absfree f a) $ absfree f b;
    89 fun letrec2_tr [Free f, Free x, Free y, a, b] =
    80 fun letrec2_tr [Free f, Free x, Free y, a, b] =
    90   Syntax.const \<^const_syntax>\<open>letrec2\<close> $ absfree x (absfree y (absfree f a)) $ absfree f b;
    81   Syntax.const \<^const_syntax>\<open>letrec2\<close> $ absfree x (absfree y (absfree f a)) $ absfree f b;
   119       Free(f',SS) $ Free(x',T) $ Free(y',U) $ Free(z',V) $ a' $ b'
   110       Free(f',SS) $ Free(x',T) $ Free(y',U) $ Free(z',V) $ a' $ b'
   120   end;
   111   end;
   121 \<close>
   112 \<close>
   122 
   113 
   123 parse_translation \<open>
   114 parse_translation \<open>
   124  [(\<^syntax_const>\<open>_let\<close>, K let_tr),
   115   [(\<^syntax_const>\<open>_letrec\<close>, K letrec_tr),
   125   (\<^syntax_const>\<open>_letrec\<close>, K letrec_tr),
   116    (\<^syntax_const>\<open>_letrec2\<close>, K letrec2_tr),
   126   (\<^syntax_const>\<open>_letrec2\<close>, K letrec2_tr),
   117    (\<^syntax_const>\<open>_letrec3\<close>, K letrec3_tr)]
   127   (\<^syntax_const>\<open>_letrec3\<close>, K letrec3_tr)]
       
   128 \<close>
   118 \<close>
   129 
   119 
   130 print_translation \<open>
   120 print_translation \<open>
   131  [(\<^const_syntax>\<open>let\<close>, K let_tr'),
   121  [(\<^const_syntax>\<open>letrec\<close>, K letrec_tr'),
   132   (\<^const_syntax>\<open>letrec\<close>, K letrec_tr'),
       
   133   (\<^const_syntax>\<open>letrec2\<close>, K letrec2_tr'),
   122   (\<^const_syntax>\<open>letrec2\<close>, K letrec2_tr'),
   134   (\<^const_syntax>\<open>letrec3\<close>, K letrec3_tr')]
   123   (\<^const_syntax>\<open>letrec3\<close>, K letrec3_tr')]
   135 \<close>
   124 \<close>
   136 
   125 
   137 
   126