* [Caml-list] Assert fail in partial application
@ 2004-06-10 8:43 Diego Olivier Fernandez Pons
2004-06-10 9:05 ` Basile Starynkevitch [local]
` (4 more replies)
0 siblings, 5 replies; 10+ messages in thread
From: Diego Olivier Fernandez Pons @ 2004-06-10 8:43 UTC (permalink / raw)
To: caml-list
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).
Diego 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
@ 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 9:05 ` Basile Starynkevitch [local]
@ 2004-06-10 9:15 ` Diego Olivier Fernandez Pons
2004-06-10 15:04 ` Richard Jones
2004-06-17 8:32 ` Jean-Christophe Filliatre
1 sibling, 1 reply; 10+ messages in thread
From: Diego Olivier Fernandez Pons @ 2004-06-10 9:15 UTC (permalink / raw)
To: Basile Starynkevitch [local]; +Cc: caml-list
Bonjour,
> You might try to code [...]
My question wasn't correctly formulated. What I want is :
#if defined DEBUGMODE
let f = function x -> ... [explicit partial application]
#else
let f = fun x y -> ...
#endif
Diego 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 9:15 ` Diego Olivier Fernandez Pons
@ 2004-06-10 15:04 ` Richard Jones
0 siblings, 0 replies; 10+ messages in thread
From: Richard Jones @ 2004-06-10 15:04 UTC (permalink / raw)
Cc: caml-list
On Thu, Jun 10, 2004 at 11:15:54AM +0200, Diego Olivier Fernandez Pons wrote:
> Bonjour,
>
> > You might try to code [...]
>
> My question wasn't correctly formulated. What I want is :
>
> #if defined DEBUGMODE
> let f = function x -> ... [explicit partial application]
> #else
> let f = fun x y -> ...
> #endif
You can preprocess with cpp, or camlp4's pa_ifdef.
See this example:
http://pauillac.inria.fr/~aschmitt/cwn/2003.09.02.html#4
Rich.
--
Richard Jones. http://www.annexia.org/ http://www.j-london.com/
Merjis Ltd. http://www.merjis.com/ - improving website return on investment
"One serious obstacle to the adoption of good programming languages is
the notion that everything has to be sacrificed for speed. In computer
languages as in life, speed kills." -- Mike Vanier
-------------------
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
* Re: [Caml-list] Assert fail in partial application
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-17 13:13 ` Damien Doligez
1 sibling, 1 reply; 10+ messages in thread
From: Jean-Christophe Filliatre @ 2004-06-17 8:32 UTC (permalink / raw)
To: Basile Starynkevitch [local]; +Cc: Diego Olivier Fernandez Pons, caml-list
Basile Starynkevitch [local] writes:
>
> Assert has nothing magic (except that it passes the file position to
> the Assert+failure exception). It could be implemented as a camlp4
> macro.
Apart from "assert false" which has a special typing rule (it has type
'a not unit) and a special compilation (cannot be removed when
-noassert is set).
--
Jean-Christophe
-------------------
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-17 8:32 ` Jean-Christophe Filliatre
@ 2004-06-17 13:13 ` Damien Doligez
0 siblings, 0 replies; 10+ messages in thread
From: Damien Doligez @ 2004-06-17 13:13 UTC (permalink / raw)
To: Liste Caml
On Jun 17, 2004, at 10:32, Jean-Christophe Filliatre wrote:
> Basile Starynkevitch [local] writes:
>>
>> Assert has nothing magic (except that it passes the file position to
>> the Assert+failure exception). It could be implemented as a camlp4
>> macro.
>
> Apart from "assert false" which has a special typing rule (it has type
> 'a not unit) and a special compilation (cannot be removed when
> -noassert is set).
Both features can be easily implemented with camlp4. The real problem
in implementing assert within camlp4 is the fact that the asserted
condition is typechecked even if -noassert is set, although this is
not an unsolvable problem.
-- Damien
-------------------
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
end of thread, other threads:[~2004-06-17 13:13 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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-10 15:04 ` Richard Jones
2004-06-17 8:32 ` Jean-Christophe Filliatre
2004-06-17 13:13 ` Damien Doligez
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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox