Re: Making "match" catch exceptions

From: Date: Fri, 26 Mar 2021 22:00:28 +0000
Subject: Re: Making "match" catch exceptions
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-113806@lists.php.net to get a copy of this message
On 26/03/2021 16:45, Olle Härstedt wrote:
That made me think of a recent extension to OCaml which makes it possible to catch exceptions in a match-expressions (here's one blog post about it: https://blog.janestreet.com/pattern-matching-and-exception-handling-unite/).
That's an interesting idea. I wonder if it would provide a way to implement the "data-flow" or "expression context" exception handling I was discussing on a different thread recently. Looking at my previous example: try {    $foo = doSomething() + $bar; } catch ( SomeException $e ) {    $foo = $bar; } Would become something like this: $foo = match($temp = doSomething()) {    exception SomeException => 0,    default => $temp } + $bar; Hm, that's not the most elegant; even if we could avoid the $temp assignment, the "default to myself" seems superfluous for this use case. I can definitely see the feature having its use cases, though, was just kicking this around as a thought experiment. Regards, -- Rowan Tommins [IMSoP]

« previous php.internals (#113806) next »