From: Yaron Minsky <yminsky@janestreet.com>
To: Gabriel Scherer <gabriel.scherer@gmail.com>
Cc: "Richard W.M. Jones" <rich@annexia.org>,
octachron <octa@polychoron.fr>,
"caml-list@inria.fr" <caml-list@inria.fr>,
hugo heuzard <hugo.heuzard@gmail.com>
Subject: Re: [Caml-list] What if exn was not an open type?
Date: Sun, 5 Nov 2017 16:48:09 -0500 [thread overview]
Message-ID: <CACLX4jQ5hxfhJgzLPkJCpKVpqCPubX0N=+qcbHLH3CV=fkhMjA@mail.gmail.com> (raw)
In-Reply-To: <CAPFanBGv-YkSVdeaOy-wqGYFSOuo4X3J0ACeX3jP6mk580ydjQ@mail.gmail.com>
Yeah, this is a general problem with exception-catching idioms. We
rand into effectively the same issue with respect to the Base's Map
and Set implementations, which are rather slow on JavaScript. We
haven't rewritten those to a more efficient style yet, though.
y
On Sun, Nov 5, 2017 at 3:49 PM, Gabriel Scherer
<gabriel.scherer@gmail.com> wrote:
> We also have return-by-local-exceptions in Batteries (the BatReturn
> module), but reports from js_of_ocaml users (namely, Clément
> Pit-Claudel) is that this style gets translated to extremely slow
> Javascript code -- functions from Batteries using this style (string
> search functions in particular) were a performance bottleneck on the
> javascript backend. I fixed the issue by rewriting all uses of
> BatReturn in Batteries libraries themselves.
> Long-term, it would be better to have Javascript backends produce
> better code on this, but I think it is rather difficult -- it is easy
> to compile efficiently local exceptions that are raised in the same
> basic block, but with_return takes a callback so you have to both
> inline and specialize before you are within reach of the optimization.
>
> On Sun, Nov 5, 2017 at 7:39 PM, Yaron Minsky <yminsky@janestreet.com> wrote:
>> FWIW, this idiom is supported by Base.
>>
>> https://github.com/janestreet/base/blob/master/src/with_return.mli
>>
>> I notice we're not yet using the unboxed attribute, though, so we
>> should fix that...
>>
>> y
>>
>> On Sun, Nov 5, 2017 at 12:41 PM, Richard W.M. Jones <rich@annexia.org> wrote:
>>> On Sat, Nov 04, 2017 at 08:16:17PM +0100, octachron wrote:
>>>> On 04/11/2017 19:44, Richard W.M. Jones wrote:
>>>> > The problem is that the return statement could be called from many
>>>> > contexts, all with different types. The compiler expects to unify all
>>>> > these types (as the same type 'b) which is not possible.
>>>> This issue can be solved by making the type of return more precise,
>>>> capturing the fact that return always raises:
>>>>
>>>> type 'a return = { return: 'b. 'a -> 'b } [@@unboxed]
>>>> let with_return (type b) f =
>>>> let exception Return of b in
>>>> try f {return = (fun y -> raise (Return y))} with Return y -> y;;
>>>>
>>>> It becomes then possible to write
>>>>
>>>> let f () =
>>>> with_return (fun {return} ->
>>>> if false then return "error";
>>>> let a =
>>>> match Some "abc" with
>>>> | None -> return "another error"
>>>> | Some a -> a in
>>>> a
>>>> )
>>>
>>> This one works great, thanks.
>>>
>>> Rich.
>>>
>>> --
>>> Richard Jones
>>>
>>> --
>>> 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
>>
>> --
>> 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
next prev parent reply other threads:[~2017-11-05 21:48 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-20 9:56 Malcolm Matalka
2017-10-20 10:55 ` David Allsopp
2017-10-20 11:21 ` Ivan Gotovchits
2017-10-20 11:38 ` Simon Cruanes
2017-10-20 16:54 ` Malcolm Matalka
2017-10-20 19:47 ` Simon Cruanes
2017-10-21 21:15 ` Malcolm Matalka
2017-10-24 13:30 ` Richard W.M. Jones
2017-10-24 19:02 ` Petter A. Urkedal
2017-11-04 18:44 ` Richard W.M. Jones
2017-11-04 18:48 ` SP
2017-11-04 18:53 ` Richard W.M. Jones
2017-11-04 19:03 ` SP
2017-11-04 19:01 ` Max Mouratov
2017-11-04 19:16 ` octachron
2017-11-05 17:41 ` Richard W.M. Jones
2017-11-05 18:39 ` Yaron Minsky
2017-11-05 20:49 ` Gabriel Scherer
2017-11-05 21:48 ` Yaron Minsky [this message]
2017-11-05 21:53 ` Petter A. Urkedal
2017-11-05 18:02 ` Petter A. Urkedal
2017-11-05 18:24 ` Richard W.M. Jones
2017-11-05 18:55 ` Petter A. Urkedal
[not found] ` <CALa9pHQ-nhWf4T0U5gDiKTduPiEeXSZPQ=DY6N1YNbCXqRohPQ@mail.gmail.com>
2017-10-25 8:35 ` Richard W.M. Jones
2017-10-25 9:12 ` Philippe Veber
2017-10-25 14:52 ` Richard W.M. Jones
2017-10-25 16:37 ` Ivan Gotovchits
2017-10-25 17:47 ` SP
2017-10-26 8:06 ` Malcolm Matalka
2017-10-26 8:11 ` Xavier Leroy
2017-10-25 13:36 ` Ivan Gotovchits
2017-10-26 7:31 ` Petter A. Urkedal
2017-10-27 13:58 ` Oleg
2017-10-27 14:24 ` Philippe Veber
2017-10-27 14:49 ` Leo White
2017-11-01 7:16 ` Oleg
2017-11-04 17:52 ` Philippe Veber
2017-10-20 17:07 ` Malcolm Matalka
2017-10-21 21:28 ` Nathan Moreau
2017-10-22 12:39 ` Malcolm Matalka
2017-10-22 13:08 ` Nathan Moreau
2017-10-24 11:11 ` SP
2017-10-24 11:16 ` Gabriel Scherer
2017-10-25 11:30 ` Malcolm Matalka
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CACLX4jQ5hxfhJgzLPkJCpKVpqCPubX0N=+qcbHLH3CV=fkhMjA@mail.gmail.com' \
--to=yminsky@janestreet.com \
--cc=caml-list@inria.fr \
--cc=gabriel.scherer@gmail.com \
--cc=hugo.heuzard@gmail.com \
--cc=octa@polychoron.fr \
--cc=rich@annexia.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox