Browse thread
[Caml-list] Assert fail in partial application
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Basile Starynkevitch [local] <basile.starynkevitch@i...> |
| Subject: | Re: [Caml-list] Assert fail in partial application |
Hello All,
On Thu, Jun 10, 2004 at 10:43:06AM +0200, Diego Olivier Fernandez Pons wrote:
>
> I would like a function that contains an assert to fail in partial
> application and the test are still removed when compiling in noassert
> mode
>
> # let f = fun x y -> assert (x > 0); assert (y > 0); x + y
> val f : int -> int -> int
> # f 0;;
> - : int -> int = <fun>
> # f 0 0;;
> Exception: Assert_failure (" ", 1, 19).
>
assert is only a syntactical sugar for if <asserted-condition> then ()
else raise Assert_failure (<sourcefileposition>)
You might try to code
let f = fun x ->
begin
assert(x>0);
fun y -> begin
assert(y>0);
x + y
end
end;;
# f 0;;
Exception: Assert_failure ("", 4, 7).
# f 1;;
- : int -> int = <fun>
# f 1 2;;
- : int = 3
# f 1 0;;
Exception: Assert_failure ("", 6, 9).
Assert has nothing magic (except that it passes the file position to
the Assert+failure exception). It could be implemented as a camlp4
macro.
Regards.
--
Basile STARYNKEVITCH -- basile dot starynkevitch at inria dot fr
Project cristal.inria.fr - (temporarily)
http://cristal.inria.fr/~starynke --- all opinions are only mine
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners