* [Caml-list] Lazyness and exceptions
@ 2012-11-22 10:29 Jean-vincent.Loddo
2012-11-22 10:33 ` Török Edwin
0 siblings, 1 reply; 4+ messages in thread
From: Jean-vincent.Loddo @ 2012-11-22 10:29 UTC (permalink / raw)
To: caml-list
Hello,
I have observed a strange behaviour of lazy values when an exception is
raised. Here a minimal code that reproduces the behaviour:
# let action =
let thunk () =
Printf.printf "aaa\n";
failwith "bbb"
in
lazy (thunk ());;
val action : unit lazy_t = <lazy>
# Lazy.force action ;;
aaa
Exception: Failure "bbb".
# Lazy.force action ;;
Exception: Failure "bbb".
The lazy value seems to be (correctly) not re-evaluated but the
exception is (strangely) raised again. Why does this happen?
Jean-Vincent Loddo
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] Lazyness and exceptions
2012-11-22 10:29 [Caml-list] Lazyness and exceptions Jean-vincent.Loddo
@ 2012-11-22 10:33 ` Török Edwin
2012-11-22 10:37 ` David House
0 siblings, 1 reply; 4+ messages in thread
From: Török Edwin @ 2012-11-22 10:33 UTC (permalink / raw)
To: caml-list
On 11/22/2012 12:29 PM, Jean-vincent.Loddo@lipn.univ-paris13.fr wrote:
> Hello,
>
> I have observed a strange behaviour of lazy values when an exception is raised. Here a minimal code that reproduces the behaviour:
>
> # let action =
> let thunk () =
> Printf.printf "aaa\n";
> failwith "bbb"
> in
> lazy (thunk ());;
>
> val action : unit lazy_t = <lazy>
>
> # Lazy.force action ;;
> aaa
> Exception: Failure "bbb".
>
> # Lazy.force action ;;
> Exception: Failure "bbb".
>
> The lazy value seems to be (correctly) not re-evaluated but the exception is (strangely) raised again. Why does this happen?
Its the documented behavior:
http://caml.inria.fr/pub/docs/manual-ocaml/libref/Lazy.html
Unfortunately the original backtrace will be lost.
--Edwin
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] Lazyness and exceptions
2012-11-22 10:33 ` Török Edwin
@ 2012-11-22 10:37 ` David House
2012-11-22 10:57 ` Jean-vincent.Loddo
0 siblings, 1 reply; 4+ messages in thread
From: David House @ 2012-11-22 10:37 UTC (permalink / raw)
To: Török Edwin; +Cc: OCaml Mailing List
In other words: what alternative semantics would you actually want?
On Thu, Nov 22, 2012 at 10:33 AM, Török Edwin <edwin+ml-ocaml@etorok.net> wrote:
> On 11/22/2012 12:29 PM, Jean-vincent.Loddo@lipn.univ-paris13.fr wrote:
>> Hello,
>>
>> I have observed a strange behaviour of lazy values when an exception is raised. Here a minimal code that reproduces the behaviour:
>>
>> # let action =
>> let thunk () =
>> Printf.printf "aaa\n";
>> failwith "bbb"
>> in
>> lazy (thunk ());;
>>
>> val action : unit lazy_t = <lazy>
>>
>> # Lazy.force action ;;
>> aaa
>> Exception: Failure "bbb".
>>
>> # Lazy.force action ;;
>> Exception: Failure "bbb".
>>
>> The lazy value seems to be (correctly) not re-evaluated but the exception is (strangely) raised again. Why does this happen?
>
> Its the documented behavior:
> http://caml.inria.fr/pub/docs/manual-ocaml/libref/Lazy.html
>
> Unfortunately the original backtrace will be lost.
>
> --Edwin
>
> --
> Caml-list mailing list. Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Caml-list] Lazyness and exceptions
2012-11-22 10:37 ` David House
@ 2012-11-22 10:57 ` Jean-vincent.Loddo
0 siblings, 0 replies; 4+ messages in thread
From: Jean-vincent.Loddo @ 2012-11-22 10:57 UTC (permalink / raw)
To: caml-list
Ok, I understand now why. In the case of my example this choice could
be discussed because of the nature of the output (unit), because it's
not clear if the exception belongs to the output domain of the function
or not (it's a semantics question). However, in the general case we
cannot provide a reasonable output without re-evaluating the expression.
Thanks.
On Thu, 22 Nov 2012 10:37:23 +0000, David House wrote:
> In other words: what alternative semantics would you actually want?
>
> On Thu, Nov 22, 2012 at 10:33 AM, Török Edwin
> <edwin+ml-ocaml@etorok.net> wrote:
>> On 11/22/2012 12:29 PM, Jean-vincent.Loddo@lipn.univ-paris13.fr
>> wrote:
>>> Hello,
>>>
>>> I have observed a strange behaviour of lazy values when an
>>> exception is raised. Here a minimal code that reproduces the
>>> behaviour:
>>>
>>> # let action =
>>> let thunk () =
>>> Printf.printf "aaa\n";
>>> failwith "bbb"
>>> in
>>> lazy (thunk ());;
>>>
>>> val action : unit lazy_t = <lazy>
>>>
>>> # Lazy.force action ;;
>>> aaa
>>> Exception: Failure "bbb".
>>>
>>> # Lazy.force action ;;
>>> Exception: Failure "bbb".
>>>
>>> The lazy value seems to be (correctly) not re-evaluated but the
>>> exception is (strangely) raised again. Why does this happen?
>>
>> Its the documented behavior:
>> http://caml.inria.fr/pub/docs/manual-ocaml/libref/Lazy.html
>>
>> Unfortunately the original backtrace will be lost.
>>
>> --Edwin
>>
>> --
>> Caml-list mailing list. Subscription management and archives:
>> https://sympa.inria.fr/sympa/arc/caml-list
>> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>> Bug reports: http://caml.inria.fr/bin/caml-bugs
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-11-22 10:57 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-22 10:29 [Caml-list] Lazyness and exceptions Jean-vincent.Loddo
2012-11-22 10:33 ` Török Edwin
2012-11-22 10:37 ` David House
2012-11-22 10:57 ` Jean-vincent.Loddo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox