package monolith

  1. Overview
  2. Docs

Source file BuiltinExn.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
(******************************************************************************)
(*                                                                            *)
(*                                  Monolith                                  *)
(*                                                                            *)
(*                              François Pottier                              *)
(*                                                                            *)
(*  Copyright Inria. All rights reserved. This file is distributed under the  *)
(*  terms of the GNU Lesser General Public License as published by the Free   *)
(*  Software Foundation, either version 3 of the License, or (at your         *)
(*  option) any later version, as described in the file LICENSE.              *)
(*                                                                            *)
(******************************************************************************)

open Spec

(* -------------------------------------------------------------------------- *)

(* A concrete type: [exn]. *)

(* [exn] is used in the definition of the combinator [(^!>)]. *)

(* We view [exn] as a deconstructible type only, because exceptions
   are always a result that is observed, never an argument. *)

(* We equip the type [exn] with an extensible notion of equality. Initially,
   it is the default equality; this implies that when the candidate and
   reference implementations both raise an exception, they are expected to
   raise exactly the same exception. The user can override this with new
   cases. *)

let exn_eq_hook : (exn -> exn -> bool) ref =
  ref (=)

let () =
  GlobalState.register_ref exn_eq_hook

let override_exn_eq update =
  exn_eq_hook := update !exn_eq_hook

let exn_eq e1 e2 =
  !exn_eq_hook e1 e2

let print =
  Print.exn

let equal =
  exn_eq, Code.infix "=exn=" (* not a value; monomorphic *)

let exn =
  SpecDeconstructible { equal; print }
OCaml

Innovation. Community. Security.