src/HOL/Library/State_Monad.thy
changeset 24224 a5c95bbeb31d
parent 24195 7d1a16c77f7c
child 24253 3d7f74fd9fd9
equal deleted inserted replaced
24223:fa9421d52c74 24224:a5c95bbeb31d
   224   "_let x t f" => "CONST Let t (\<lambda>x. f)"
   224   "_let x t f" => "CONST Let t (\<lambda>x. f)"
   225   "_nil f" => "f"
   225   "_nil f" => "f"
   226 
   226 
   227 print_translation {*
   227 print_translation {*
   228 let
   228 let
   229   fun unfold_monad (Const (@{const_syntax mbind}, _) $ f $ g) =
   229   fun unfold_monad (Const (@{const_syntax mbind}, _) $ f $ Abs (abs as (_, ty, _))) =
   230         let
   230         let
   231           val ([(v, ty)], g') = Term.strip_abs_eta 1 g;
   231           val (v', g') = Syntax.variant_abs abs;
   232         in Const ("_mbind", dummyT) $ Free (v, ty) $ f $ unfold_monad g' end
   232         in Const ("_mbind", dummyT) $ Free (v', ty) $ f $ unfold_monad g' end
   233     | unfold_monad (Const (@{const_syntax fcomp}, _) $ f $ g) =
   233     | unfold_monad (Const (@{const_syntax fcomp}, _) $ f $ g) =
   234         Const ("_fcomp", dummyT) $ f $ unfold_monad g
   234         Const ("_fcomp", dummyT) $ f $ unfold_monad g
   235     | unfold_monad (Const (@{const_syntax Let}, _) $ f $ g) =
   235     | unfold_monad (Const (@{const_syntax Let}, _) $ f $ Abs (abs as (_, ty, _))) =
   236         let
   236         let
   237           val ([(v, ty)], g') = Term.strip_abs_eta 1 g;
   237           val (v', g') = Syntax.variant_abs abs;
   238         in Const ("_let", dummyT) $ Free (v, ty) $ f $ unfold_monad g' end
   238         in Const ("_mbind", dummyT) $ Free (v', ty) $ f $ unfold_monad g' end
   239     | unfold_monad (Const (@{const_syntax Pair}, _) $ f) =
   239     | unfold_monad (Const (@{const_syntax Pair}, _) $ f) =
   240         Const ("return", dummyT) $ f
   240         Const ("return", dummyT) $ f
   241     | unfold_monad f = f;
   241     | unfold_monad f = f;
   242   fun tr' (f::ts) =
   242   fun tr' (f::ts) =
   243     list_comb (Const ("_do", dummyT) $ unfold_monad f, ts)
   243     list_comb (Const ("_do", dummyT) $ unfold_monad f, ts)