abort execution of generated code with explicit exception message
authorAndreas Lochbihler
Thu, 08 Aug 2013 16:10:05 +0200
changeset 52910 7bfe0df532a9
parent 52909 66cc4ed9a1f2
child 52914 7a1537b54f16
child 52916 5f3faf72b62a
abort execution of generated code with explicit exception message
src/HOL/String.thy
--- a/src/HOL/String.thy	Thu Aug 08 14:55:01 2013 +0200
+++ b/src/HOL/String.thy	Thu Aug 08 16:10:05 2013 +0200
@@ -420,6 +420,19 @@
     and (Haskell) infix 4 "=="
     and (Scala) infixl 5 "=="
 
+setup {* Sign.map_naming (Name_Space.mandatory_path "Code") *}
+
+definition abort :: "literal \<Rightarrow> (unit \<Rightarrow> 'a) \<Rightarrow> 'a"
+where [simp, code del]: "abort _ f = f ()"
+
+setup {* Sign.map_naming Name_Space.parent_path *}
+
+code_printing constant Code.abort \<rightharpoonup>
+    (SML) "!(raise/ Fail/ _)"
+    and (OCaml) "failwith"
+    and (Haskell) "error"
+    and (Scala) "!{/ sys.error((_));/  ((_)).apply(())/ }"
+
 hide_type (open) literal
 
 end