src/HOL/Library/Heap_Monad.thy
author haftmann
Sun Apr 27 17:13:01 2008 +0200 (2008-04-27)
changeset 26752 6b276119139b
parent 26182 8262ec0e8782
child 26753 094d70c81243
permissions -rw-r--r--
corrected ML semantics
haftmann@26170
     1
(*  Title:      HOL/Library/Heap_Monad.thy
haftmann@26170
     2
    ID:         $Id$
haftmann@26170
     3
    Author:     John Matthews, Galois Connections; Alexander Krauss, Lukas Bulwahn & Florian Haftmann, TU Muenchen
haftmann@26170
     4
*)
haftmann@26170
     5
haftmann@26170
     6
header {* A monad with a polymorphic heap *}
haftmann@26170
     7
haftmann@26170
     8
theory Heap_Monad
haftmann@26170
     9
imports Heap
haftmann@26170
    10
begin
haftmann@26170
    11
haftmann@26170
    12
subsection {* The monad *}
haftmann@26170
    13
haftmann@26170
    14
subsubsection {* Monad combinators *}
haftmann@26170
    15
haftmann@26170
    16
datatype exception = Exn
haftmann@26170
    17
haftmann@26170
    18
text {* Monadic heap actions either produce values
haftmann@26170
    19
  and transform the heap, or fail *}
haftmann@26170
    20
datatype 'a Heap = Heap "heap \<Rightarrow> ('a + exception) \<times> heap"
haftmann@26170
    21
haftmann@26170
    22
primrec
haftmann@26170
    23
  execute :: "'a Heap \<Rightarrow> heap \<Rightarrow> ('a + exception) \<times> heap" where
haftmann@26170
    24
  "execute (Heap f) = f"
haftmann@26170
    25
lemmas [code del] = execute.simps
haftmann@26170
    26
haftmann@26170
    27
lemma Heap_execute [simp]:
haftmann@26170
    28
  "Heap (execute f) = f" by (cases f) simp_all
haftmann@26170
    29
haftmann@26170
    30
lemma Heap_eqI:
haftmann@26170
    31
  "(\<And>h. execute f h = execute g h) \<Longrightarrow> f = g"
haftmann@26170
    32
    by (cases f, cases g) (auto simp: expand_fun_eq)
haftmann@26170
    33
haftmann@26170
    34
lemma Heap_eqI':
haftmann@26170
    35
  "(\<And>h. (\<lambda>x. execute (f x) h) = (\<lambda>y. execute (g y) h)) \<Longrightarrow> f = g"
haftmann@26170
    36
    by (auto simp: expand_fun_eq intro: Heap_eqI)
haftmann@26170
    37
haftmann@26170
    38
lemma Heap_strip: "(\<And>f. PROP P f) \<equiv> (\<And>g. PROP P (Heap g))"
haftmann@26170
    39
proof
haftmann@26170
    40
  fix g :: "heap \<Rightarrow> ('a + exception) \<times> heap" 
haftmann@26170
    41
  assume "\<And>f. PROP P f"
haftmann@26170
    42
  then show "PROP P (Heap g)" .
haftmann@26170
    43
next
haftmann@26170
    44
  fix f :: "'a Heap" 
haftmann@26170
    45
  assume assm: "\<And>g. PROP P (Heap g)"
haftmann@26170
    46
  then have "PROP P (Heap (execute f))" .
haftmann@26170
    47
  then show "PROP P f" by simp
haftmann@26170
    48
qed
haftmann@26170
    49
haftmann@26170
    50
definition
haftmann@26170
    51
  heap :: "(heap \<Rightarrow> 'a \<times> heap) \<Rightarrow> 'a Heap" where
haftmann@26170
    52
  [code del]: "heap f = Heap (\<lambda>h. apfst Inl (f h))"
haftmann@26170
    53
haftmann@26170
    54
lemma execute_heap [simp]:
haftmann@26170
    55
  "execute (heap f) h = apfst Inl (f h)"
haftmann@26170
    56
  by (simp add: heap_def)
haftmann@26170
    57
haftmann@26170
    58
definition
haftmann@26170
    59
  run :: "'a Heap \<Rightarrow> 'a Heap" where
haftmann@26170
    60
  run_drop [code del]: "run f = f"
haftmann@26170
    61
haftmann@26170
    62
definition
haftmann@26170
    63
  bindM :: "'a Heap \<Rightarrow> ('a \<Rightarrow> 'b Heap) \<Rightarrow> 'b Heap" (infixl ">>=" 54) where
haftmann@26170
    64
  [code del]: "f >>= g = Heap (\<lambda>h. case execute f h of
haftmann@26170
    65
                  (Inl x, h') \<Rightarrow> execute (g x) h'
haftmann@26170
    66
                | r \<Rightarrow> r)"
haftmann@26170
    67
haftmann@26170
    68
notation
haftmann@26170
    69
  bindM (infixl "\<guillemotright>=" 54)
haftmann@26170
    70
haftmann@26170
    71
abbreviation
haftmann@26170
    72
  chainM :: "'a Heap \<Rightarrow> 'b Heap \<Rightarrow> 'b Heap"  (infixl ">>" 54) where
haftmann@26170
    73
  "f >> g \<equiv> f >>= (\<lambda>_. g)"
haftmann@26170
    74
haftmann@26170
    75
notation
haftmann@26170
    76
  chainM (infixl "\<guillemotright>" 54)
haftmann@26170
    77
haftmann@26170
    78
definition
haftmann@26170
    79
  return :: "'a \<Rightarrow> 'a Heap" where
haftmann@26170
    80
  [code del]: "return x = heap (Pair x)"
haftmann@26170
    81
haftmann@26170
    82
lemma execute_return [simp]:
haftmann@26170
    83
  "execute (return x) h = apfst Inl (x, h)"
haftmann@26170
    84
  by (simp add: return_def)
haftmann@26170
    85
haftmann@26170
    86
definition
haftmann@26170
    87
  raise :: "string \<Rightarrow> 'a Heap" where -- {* the string is just decoration *}
haftmann@26170
    88
  [code del]: "raise s = Heap (Pair (Inr Exn))"
haftmann@26170
    89
haftmann@26170
    90
notation (latex output)
haftmann@26170
    91
  "raise" ("\<^raw:{\textsf{raise}}>")
haftmann@26170
    92
haftmann@26170
    93
lemma execute_raise [simp]:
haftmann@26170
    94
  "execute (raise s) h = (Inr Exn, h)"
haftmann@26170
    95
  by (simp add: raise_def)
haftmann@26170
    96
haftmann@26170
    97
haftmann@26170
    98
subsubsection {* do-syntax *}
haftmann@26170
    99
haftmann@26170
   100
text {*
haftmann@26170
   101
  We provide a convenient do-notation for monadic expressions
haftmann@26170
   102
  well-known from Haskell.  @{const Let} is printed
haftmann@26170
   103
  specially in do-expressions.
haftmann@26170
   104
*}
haftmann@26170
   105
haftmann@26170
   106
nonterminals do_expr
haftmann@26170
   107
haftmann@26170
   108
syntax
haftmann@26170
   109
  "_do" :: "do_expr \<Rightarrow> 'a"
haftmann@26170
   110
    ("(do (_)//done)" [12] 100)
haftmann@26170
   111
  "_bindM" :: "pttrn \<Rightarrow> 'a \<Rightarrow> do_expr \<Rightarrow> do_expr"
haftmann@26170
   112
    ("_ <- _;//_" [1000, 13, 12] 12)
haftmann@26170
   113
  "_chainM" :: "'a \<Rightarrow> do_expr \<Rightarrow> do_expr"
haftmann@26170
   114
    ("_;//_" [13, 12] 12)
haftmann@26170
   115
  "_let" :: "pttrn \<Rightarrow> 'a \<Rightarrow> do_expr \<Rightarrow> do_expr"
haftmann@26170
   116
    ("let _ = _;//_" [1000, 13, 12] 12)
haftmann@26170
   117
  "_nil" :: "'a \<Rightarrow> do_expr"
haftmann@26170
   118
    ("_" [12] 12)
haftmann@26170
   119
haftmann@26170
   120
syntax (xsymbols)
haftmann@26170
   121
  "_bindM" :: "pttrn \<Rightarrow> 'a \<Rightarrow> do_expr \<Rightarrow> do_expr"
haftmann@26170
   122
    ("_ \<leftarrow> _;//_" [1000, 13, 12] 12)
haftmann@26170
   123
syntax (latex output)
haftmann@26170
   124
  "_do" :: "do_expr \<Rightarrow> 'a"
haftmann@26170
   125
    ("(\<^raw:{\textsf{do}}> (_))" [12] 100)
haftmann@26170
   126
  "_let" :: "pttrn \<Rightarrow> 'a \<Rightarrow> do_expr \<Rightarrow> do_expr"
haftmann@26170
   127
    ("\<^raw:\textsf{let}> _ = _;//_" [1000, 13, 12] 12)
haftmann@26170
   128
notation (latex output)
haftmann@26170
   129
  "return" ("\<^raw:{\textsf{return}}>")
haftmann@26170
   130
haftmann@26170
   131
translations
haftmann@26170
   132
  "_do f" => "CONST run f"
haftmann@26170
   133
  "_bindM x f g" => "f \<guillemotright>= (\<lambda>x. g)"
haftmann@26170
   134
  "_chainM f g" => "f \<guillemotright> g"
haftmann@26170
   135
  "_let x t f" => "CONST Let t (\<lambda>x. f)"
haftmann@26170
   136
  "_nil f" => "f"
haftmann@26170
   137
haftmann@26170
   138
print_translation {*
haftmann@26170
   139
let
haftmann@26170
   140
  fun dest_abs_eta (Abs (abs as (_, ty, _))) =
haftmann@26170
   141
        let
haftmann@26170
   142
          val (v, t) = Syntax.variant_abs abs;
haftmann@26170
   143
        in ((v, ty), t) end
haftmann@26170
   144
    | dest_abs_eta t =
haftmann@26170
   145
        let
haftmann@26170
   146
          val (v, t) = Syntax.variant_abs ("", dummyT, t $ Bound 0);
haftmann@26170
   147
        in ((v, dummyT), t) end
haftmann@26170
   148
  fun unfold_monad (Const (@{const_syntax bindM}, _) $ f $ g) =
haftmann@26170
   149
        let
haftmann@26170
   150
          val ((v, ty), g') = dest_abs_eta g;
haftmann@26170
   151
          val v_used = fold_aterms
haftmann@26170
   152
            (fn Free (w, _) => (fn s => s orelse v = w) | _ => I) g' false;
haftmann@26170
   153
        in if v_used then
haftmann@26170
   154
          Const ("_bindM", dummyT) $ Free (v, ty) $ f $ unfold_monad g'
haftmann@26170
   155
        else
haftmann@26170
   156
          Const ("_chainM", dummyT) $ f $ unfold_monad g'
haftmann@26170
   157
        end
haftmann@26170
   158
    | unfold_monad (Const (@{const_syntax chainM}, _) $ f $ g) =
haftmann@26170
   159
        Const ("_chainM", dummyT) $ f $ unfold_monad g
haftmann@26170
   160
    | unfold_monad (Const (@{const_syntax Let}, _) $ f $ g) =
haftmann@26170
   161
        let
haftmann@26170
   162
          val ((v, ty), g') = dest_abs_eta g;
haftmann@26170
   163
        in Const ("_let", dummyT) $ Free (v, ty) $ f $ unfold_monad g' end
haftmann@26170
   164
    | unfold_monad (Const (@{const_syntax Pair}, _) $ f) =
haftmann@26170
   165
        Const ("return", dummyT) $ f
haftmann@26170
   166
    | unfold_monad f = f;
haftmann@26170
   167
  fun tr' (f::ts) =
haftmann@26170
   168
    list_comb (Const ("_do", dummyT) $ unfold_monad f, ts)
haftmann@26170
   169
in [(@{const_syntax "run"}, tr')] end;
haftmann@26170
   170
*}
haftmann@26170
   171
haftmann@26170
   172
subsubsection {* Plain evaluation *}
haftmann@26170
   173
haftmann@26170
   174
definition
haftmann@26170
   175
  evaluate :: "'a Heap \<Rightarrow> 'a"
haftmann@26170
   176
where
haftmann@26170
   177
  [code del]: "evaluate f = (case execute f Heap.empty
haftmann@26170
   178
    of (Inl x, _) \<Rightarrow> x)"
haftmann@26170
   179
haftmann@26170
   180
haftmann@26170
   181
subsection {* Monad properties *}
haftmann@26170
   182
haftmann@26170
   183
subsubsection {* Superfluous runs *}
haftmann@26170
   184
haftmann@26170
   185
text {* @{term run} is just a doodle *}
haftmann@26170
   186
haftmann@26170
   187
lemma run_simp [simp]:
haftmann@26170
   188
  "\<And>f. run (run f) = run f"
haftmann@26170
   189
  "\<And>f g. run f \<guillemotright>= g = f \<guillemotright>= g"
haftmann@26170
   190
  "\<And>f g. run f \<guillemotright> g = f \<guillemotright> g"
haftmann@26170
   191
  "\<And>f g. f \<guillemotright>= (\<lambda>x. run g) = f \<guillemotright>= (\<lambda>x. g)"
haftmann@26170
   192
  "\<And>f g. f \<guillemotright> run g = f \<guillemotright> g"
haftmann@26170
   193
  "\<And>f. f = run g \<longleftrightarrow> f = g"
haftmann@26170
   194
  "\<And>f. run f = g \<longleftrightarrow> f = g"
haftmann@26170
   195
  unfolding run_drop by rule+
haftmann@26170
   196
haftmann@26170
   197
subsubsection {* Monad laws *}
haftmann@26170
   198
haftmann@26170
   199
lemma return_bind: "return x \<guillemotright>= f = f x"
haftmann@26170
   200
  by (simp add: bindM_def return_def)
haftmann@26170
   201
haftmann@26170
   202
lemma bind_return: "f \<guillemotright>= return = f"
haftmann@26170
   203
proof (rule Heap_eqI)
haftmann@26170
   204
  fix h
haftmann@26170
   205
  show "execute (f \<guillemotright>= return) h = execute f h"
haftmann@26170
   206
    by (auto simp add: bindM_def return_def split: sum.splits prod.splits)
haftmann@26170
   207
qed
haftmann@26170
   208
haftmann@26170
   209
lemma bind_bind: "(f \<guillemotright>= g) \<guillemotright>= h = f \<guillemotright>= (\<lambda>x. g x \<guillemotright>= h)"
haftmann@26170
   210
  by (rule Heap_eqI) (auto simp add: bindM_def split: split: sum.splits prod.splits)
haftmann@26170
   211
haftmann@26170
   212
lemma bind_bind': "f \<guillemotright>= (\<lambda>x. g x \<guillemotright>= h x) = f \<guillemotright>= (\<lambda>x. g x \<guillemotright>= (\<lambda>y. return (x, y))) \<guillemotright>= (\<lambda>(x, y). h x y)"
haftmann@26170
   213
  by (rule Heap_eqI) (auto simp add: bindM_def split: split: sum.splits prod.splits)
haftmann@26170
   214
haftmann@26170
   215
lemma raise_bind: "raise e \<guillemotright>= f = raise e"
haftmann@26170
   216
  by (simp add: raise_def bindM_def)
haftmann@26170
   217
haftmann@26170
   218
haftmann@26170
   219
lemmas monad_simp = return_bind bind_return bind_bind raise_bind
haftmann@26170
   220
haftmann@26170
   221
haftmann@26170
   222
subsection {* Generic combinators *}
haftmann@26170
   223
haftmann@26170
   224
definition
haftmann@26170
   225
  liftM :: "('a \<Rightarrow> 'b) \<Rightarrow> 'a \<Rightarrow> 'b Heap"
haftmann@26170
   226
where
haftmann@26170
   227
  "liftM f = return o f"
haftmann@26170
   228
haftmann@26170
   229
definition
haftmann@26170
   230
  compM :: "('a \<Rightarrow> 'b Heap) \<Rightarrow> ('b \<Rightarrow> 'c Heap) \<Rightarrow> 'a \<Rightarrow> 'c Heap" (infixl ">>==" 54)
haftmann@26170
   231
where
haftmann@26170
   232
  "(f >>== g) = (\<lambda>x. f x \<guillemotright>= g)"
haftmann@26170
   233
haftmann@26170
   234
notation
haftmann@26170
   235
  compM (infixl "\<guillemotright>==" 54)
haftmann@26170
   236
haftmann@26170
   237
lemma liftM_collapse: "liftM f x = return (f x)"
haftmann@26170
   238
  by (simp add: liftM_def)
haftmann@26170
   239
haftmann@26170
   240
lemma liftM_compM: "liftM f \<guillemotright>== g = g o f"
haftmann@26170
   241
  by (auto intro: Heap_eqI' simp add: expand_fun_eq liftM_def compM_def bindM_def)
haftmann@26170
   242
haftmann@26170
   243
lemma compM_return: "f \<guillemotright>== return = f"
haftmann@26170
   244
  by (simp add: compM_def monad_simp)
haftmann@26170
   245
haftmann@26170
   246
lemma compM_compM: "(f \<guillemotright>== g) \<guillemotright>== h = f \<guillemotright>== (g \<guillemotright>== h)"
haftmann@26170
   247
  by (simp add: compM_def monad_simp)
haftmann@26170
   248
haftmann@26170
   249
lemma liftM_bind:
haftmann@26170
   250
  "(\<lambda>x. liftM f x \<guillemotright>= liftM g) = liftM (\<lambda>x. g (f x))"
haftmann@26170
   251
  by (rule Heap_eqI') (simp add: monad_simp liftM_def bindM_def)
haftmann@26170
   252
haftmann@26170
   253
lemma liftM_comp:
haftmann@26170
   254
  "liftM f o g = liftM (f o g)"
haftmann@26170
   255
  by (rule Heap_eqI') (simp add: liftM_def)
haftmann@26170
   256
haftmann@26170
   257
lemmas monad_simp' = monad_simp liftM_compM compM_return
haftmann@26170
   258
  compM_compM liftM_bind liftM_comp
haftmann@26170
   259
haftmann@26170
   260
primrec 
haftmann@26170
   261
  mapM :: "('a \<Rightarrow> 'b Heap) \<Rightarrow> 'a list \<Rightarrow> 'b list Heap"
haftmann@26170
   262
where
haftmann@26170
   263
  "mapM f [] = return []"
haftmann@26170
   264
  | "mapM f (x#xs) = do y \<leftarrow> f x;
haftmann@26170
   265
                        ys \<leftarrow> mapM f xs;
haftmann@26170
   266
                        return (y # ys)
haftmann@26170
   267
                     done"
haftmann@26170
   268
haftmann@26170
   269
primrec
haftmann@26170
   270
  foldM :: "('a \<Rightarrow> 'b \<Rightarrow> 'b Heap) \<Rightarrow> 'a list \<Rightarrow> 'b \<Rightarrow> 'b Heap"
haftmann@26170
   271
where
haftmann@26170
   272
  "foldM f [] s = return s"
haftmann@26170
   273
  | "foldM f (x#xs) s = f x s \<guillemotright>= foldM f xs"
haftmann@26170
   274
haftmann@26170
   275
hide (open) const heap execute
haftmann@26170
   276
haftmann@26182
   277
haftmann@26182
   278
subsection {* Code generator setup *}
haftmann@26182
   279
haftmann@26182
   280
subsubsection {* Logical intermediate layer *}
haftmann@26182
   281
haftmann@26182
   282
definition
haftmann@26182
   283
  Fail :: "message_string \<Rightarrow> exception"
haftmann@26182
   284
where
haftmann@26182
   285
  [code func del]: "Fail s = Exn"
haftmann@26182
   286
haftmann@26182
   287
definition
haftmann@26182
   288
  raise_exc :: "exception \<Rightarrow> 'a Heap"
haftmann@26182
   289
where
haftmann@26182
   290
  [code func del]: "raise_exc e = raise []"
haftmann@26182
   291
haftmann@26182
   292
lemma raise_raise_exc [code func, code inline]:
haftmann@26182
   293
  "raise s = raise_exc (Fail (STR s))"
haftmann@26182
   294
  unfolding Fail_def raise_exc_def raise_def ..
haftmann@26182
   295
haftmann@26182
   296
hide (open) const Fail raise_exc
haftmann@26182
   297
haftmann@26182
   298
haftmann@26182
   299
subsubsection {* SML *}
haftmann@26182
   300
haftmann@26752
   301
code_type Heap (SML "unit/ ->/ _")
haftmann@26752
   302
term "op \<guillemotright>="
haftmann@26182
   303
code_const Heap (SML "raise/ (Fail/ \"bare Heap\")")
haftmann@26752
   304
code_monad run "op \<guillemotright>=" "()" SML
haftmann@26182
   305
code_const run (SML "_")
haftmann@26752
   306
code_const return (SML "(fn/ ()/ =>/ _)")
haftmann@26182
   307
code_const "Heap_Monad.Fail" (SML "Fail")
haftmann@26752
   308
code_const "Heap_Monad.raise_exc" (SML "(fn/ ()/ =>/ raise/ _)")
haftmann@26182
   309
haftmann@26182
   310
haftmann@26182
   311
subsubsection {* OCaml *}
haftmann@26182
   312
haftmann@26182
   313
code_type Heap (OCaml "_")
haftmann@26182
   314
code_const Heap (OCaml "failwith/ \"bare Heap\"")
haftmann@26752
   315
code_monad run "op \<guillemotright>=" "()" OCaml
haftmann@26182
   316
code_const run (OCaml "_")
haftmann@26752
   317
code_const return (OCaml "(fn/ ()/ =>/ _)")
haftmann@26182
   318
code_const "Heap_Monad.Fail" (OCaml "Failure")
haftmann@26752
   319
code_const "Heap_Monad.raise_exc" (OCaml "(fn/ ()/ =>/ raise/ _)")
haftmann@26182
   320
haftmann@26182
   321
code_reserved OCaml Failure raise
haftmann@26182
   322
haftmann@26182
   323
haftmann@26182
   324
subsubsection {* Haskell *}
haftmann@26182
   325
haftmann@26182
   326
text {* Adaption layer *}
haftmann@26182
   327
haftmann@26182
   328
code_include Haskell "STMonad"
haftmann@26182
   329
{*import qualified Control.Monad;
haftmann@26182
   330
import qualified Control.Monad.ST;
haftmann@26182
   331
import qualified Data.STRef;
haftmann@26182
   332
import qualified Data.Array.ST;
haftmann@26182
   333
haftmann@26182
   334
type ST s a = Control.Monad.ST.ST s a;
haftmann@26182
   335
type STRef s a = Data.STRef.STRef s a;
haftmann@26182
   336
type STArray s a = Data.Array.ST.STArray s Integer a;
haftmann@26182
   337
haftmann@26182
   338
runST :: (forall s. ST s a) -> a;
haftmann@26182
   339
runST s = Control.Monad.ST.runST s;
haftmann@26182
   340
haftmann@26182
   341
newSTRef = Data.STRef.newSTRef;
haftmann@26182
   342
readSTRef = Data.STRef.readSTRef;
haftmann@26182
   343
writeSTRef = Data.STRef.writeSTRef;
haftmann@26182
   344
haftmann@26182
   345
newArray :: (Integer, Integer) -> a -> ST s (STArray s a);
haftmann@26182
   346
newArray = Data.Array.ST.newArray;
haftmann@26182
   347
haftmann@26182
   348
newListArray :: (Integer, Integer) -> [a] -> ST s (STArray s a);
haftmann@26182
   349
newListArray = Data.Array.ST.newListArray;
haftmann@26182
   350
haftmann@26182
   351
length :: STArray s a -> ST s Integer;
haftmann@26182
   352
length a = Control.Monad.liftM snd (Data.Array.ST.getBounds a);
haftmann@26182
   353
haftmann@26182
   354
readArray :: STArray s a -> Integer -> ST s a;
haftmann@26182
   355
readArray = Data.Array.ST.readArray;
haftmann@26182
   356
haftmann@26182
   357
writeArray :: STArray s a -> Integer -> a -> ST s ();
haftmann@26182
   358
writeArray = Data.Array.ST.writeArray;*}
haftmann@26182
   359
haftmann@26182
   360
code_reserved Haskell ST STRef Array
haftmann@26182
   361
  runST
haftmann@26182
   362
  newSTRef reasSTRef writeSTRef
haftmann@26182
   363
  newArray newListArray bounds readArray writeArray
haftmann@26182
   364
haftmann@26182
   365
text {* Monad *}
haftmann@26182
   366
haftmann@26182
   367
code_type Heap (Haskell "ST '_s _")
haftmann@26182
   368
code_const Heap (Haskell "error \"bare Heap\")")
haftmann@26182
   369
code_const evaluate (Haskell "runST")
haftmann@26752
   370
code_monad run "op \<guillemotright>=" Haskell
haftmann@26182
   371
code_const return (Haskell "return")
haftmann@26182
   372
code_const "Heap_Monad.Fail" (Haskell "_")
haftmann@26182
   373
code_const "Heap_Monad.raise_exc" (Haskell "error")
haftmann@26182
   374
haftmann@26170
   375
end