1 (* Copyright (C
) 1999-2006 Henry Cejtin
, Matthew Fluet
, Suresh
2 * Jagannathan
, and Stephen Weeks
.
4 * MLton is released under a BSD
-style license
.
5 * See the file MLton
-LICENSE for details
.
8 structure Assert
: ASSERT
=
10 val debug
= MLton
.debug
orelse (not MLton
.isMLton
)
12 fun fail msg
= Error
.bug (concat
["assertion failure: ", msg
])
14 fun assert (msg
: string, f
: unit
-> bool): unit
=
15 if debug
andalso not (f () handle _
=> false)
19 fun assert
' (msg
, b
) = assert (msg
, fn () => b
)
21 val ('a
, 'b
) assertFun
':
24 * ('a
-> bool * ('b
-> bool * 'b
))
26 (* Can
't
do what I really want because
of the value restriction
.
27 * Would like to write
:
28 * if debug
then (fn ... => ...) else (fn ... => ...).
33 let val (yes
, check
) = check a
34 val _
= assert
' (concat
[msg
, " argument"], yes
)
35 val (yes
, b
) = check (f a
)
36 in assert
' (concat
[msg
, " result"], yes
)
43 check
: 'a
-> bool * ('b
-> bool)): 'a
-> 'b
=
45 fn a
=> let val (yes
, check
) = check a
46 in (yes
, fn b
=> (check b
, b
))
51 check
: 'a
-> bool * ('b
-> (bool * ('c
-> bool)))) =
54 fn a
=> let val (yes
, check
) = check a
56 fn bc
=> (true, assertFun (msg
, bc
, check
)))