* Re: [Caml-list] Assert fail in partial application
2004-06-10 8:43 [Caml-list] Assert fail in partial application Diego Olivier Fernandez Pons
@ 2004-06-10 9:05 ` Basile Starynkevitch [local]
2004-06-10 9:15 ` Diego Olivier Fernandez Pons
2004-06-17 8:32 ` Jean-Christophe Filliatre
2004-06-10 9:05 ` Benjamin Monate
` (3 subsequent siblings)
4 siblings, 2 replies; 10+ messages in thread
From: Basile Starynkevitch [local] @ 2004-06-10 9:05 UTC (permalink / raw)
To: Diego Olivier Fernandez Pons, caml-list
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
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Caml-list] Assert fail in partial application
2004-06-10 8:43 [Caml-list] Assert fail in partial application Diego Olivier Fernandez Pons
2004-06-10 9:05 ` Basile Starynkevitch [local]
@ 2004-06-10 9:05 ` Benjamin Monate
2004-06-10 9:10 ` Olivier Andrieu
` (2 subsequent siblings)
4 siblings, 0 replies; 10+ messages in thread
From: Benjamin Monate @ 2004-06-10 9:05 UTC (permalink / raw)
To: caml-list
Bonjour,
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).
What about :
Objective Caml version 3.07+2
# let f x = assert (x>0) ; fun y -> assert (y>0) ; x+y;;
val f : int -> int -> int = <fun>
# f 0;
;;
Exception: Assert_failure ("", 1, 10).
# f 2 0 ;;
Exception: Assert_failure ("", 1, 34).
Hope this helps
--
| Benjamin Monate
-------------------
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
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Caml-list] Assert fail in partial application
2004-06-10 8:43 [Caml-list] Assert fail in partial application Diego Olivier Fernandez Pons
2004-06-10 9:05 ` Basile Starynkevitch [local]
2004-06-10 9:05 ` Benjamin Monate
@ 2004-06-10 9:10 ` Olivier Andrieu
2004-06-10 9:10 ` Christophe TROESTLER
2004-06-10 20:56 ` Brian Hurt
4 siblings, 0 replies; 10+ messages in thread
From: Olivier Andrieu @ 2004-06-10 9:10 UTC (permalink / raw)
To: Diego.FERNANDEZ_PONS; +Cc: caml-list
Diego Olivier Fernandez Pons [Thu, 10 Jun 2004]:
> Bonjour,
>
> 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).
nothing specific to assert here, regular partial application works:
# let f = fun x -> assert (x > 0) ; fun y -> assert (y > 0) ; x + y ;;
val f : int -> int -> int = <fun>
# f 0 ;;
Exception: Assert_failure ("", 1, 17).
--
Olivier
-------------------
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
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Caml-list] Assert fail in partial application
2004-06-10 8:43 [Caml-list] Assert fail in partial application Diego Olivier Fernandez Pons
` (2 preceding siblings ...)
2004-06-10 9:10 ` Olivier Andrieu
@ 2004-06-10 9:10 ` Christophe TROESTLER
2004-06-10 20:56 ` Brian Hurt
4 siblings, 0 replies; 10+ messages in thread
From: Christophe TROESTLER @ 2004-06-10 9:10 UTC (permalink / raw)
To: Diego.FERNANDEZ_PONS; +Cc: caml-list
On Thu, 10 Jun 2004, Diego Olivier Fernandez Pons <Diego.FERNANDEZ_PONS@etu.upmc.fr> wrote:
>
> let f = fun x y -> assert (x > 0); assert (y > 0); x + y
let f = fun x -> assert (x > 0); fun y -> assert (y > 0); x + y;;
-------------------
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
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [Caml-list] Assert fail in partial application
2004-06-10 8:43 [Caml-list] Assert fail in partial application Diego Olivier Fernandez Pons
` (3 preceding siblings ...)
2004-06-10 9:10 ` Christophe TROESTLER
@ 2004-06-10 20:56 ` Brian Hurt
4 siblings, 0 replies; 10+ messages in thread
From: Brian Hurt @ 2004-06-10 20:56 UTC (permalink / raw)
To: Diego Olivier Fernandez Pons; +Cc: caml-list
On Thu, 10 Jun 2004, Diego Olivier Fernandez Pons wrote:
> Bonjour,
>
> 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).
This seems to work:
# let f x = assert (x > 0); fun y -> x + y;;
val f : int -> int -> int = <fun>
# f 0;;
Exception: Assert_failure ("", 1, 10).
#
--
"Usenet is like a herd of performing elephants with diarrhea -- massive,
difficult to redirect, awe-inspiring, entertaining, and a source of
mind-boggling amounts of excrement when you least expect it."
- Gene Spafford
Brian
-------------------
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
^ permalink raw reply [flat|nested] 10+ messages in thread