« first day (3606 days earlier)      last day (1336 days later) » 
00:00 - 23:0023:00 - 00:00

12:48 AM
The problem with working on experimental syntax is that PHPStorm gets really confused... :-)
 
 
2 hours later…
2:28 AM
@IluTov When you're around tomorrow, ping me. I have some thoughts on pattern matching, match(), enums, et al I want to rubber duck with you.
 
3:15 AM
vashdiplomchikmeele ・ *General Issues ・ #80033
 
 
2 hours later…
5:11 AM
@PeeHaa I got a $100 donation tonight while streaming! I is pro now!
 
 
3 hours later…
8:24 AM
@Crell I'm here but I think you're gonna be sleeping for another couple of hours :)
 
@Trowski Your simple API would work, in fact it could be even more minimalistic. You do not need resume() and throw() because that is already covered by the callback passed to onResolve(). This is the one thing I do not like about it, just an arbitrary callback seems a little too generic to me. What do you think about this instead (almost the same thing) gist.github.com/kooldev/e29b4e024528eae16c57a49b4d4a0790
 
@StatikStasis Remember us when you're at the top.
 
8:59 AM
PHP8 crashes apache web server ・ Apache2 related ・ #80034
 
 
1 hour later…
10:04 AM
o/
Does somebody know a self hosted alternative to 3v4l? I've made some changes to php-src and I would like to showcase them with a simple online editor.
 
10:40 AM
@GabrielCaruso @Sara When does beta 3 get tagged? Just asking because I'd like PR to be merged by then.
 
cmb
10:56 AM
@IluTov that's supposed to happen on Tuesday
 
@cmb Ok, thanks!
 
 
1 hour later…
12:03 PM
@StatikStasis nice job
 
Anyone knows what does "trade-in" means?
 
apple.com/shop/trade-in you sell them your old phone
 
12:19 PM
@Shafizadeh means you exchange your old phone
 
you mean I have to deliver my cellphone and get a new one plus paying some extra money?
why they want my old cellphone?
 
@Shafizadeh Yeah, you can get a new one for less money if you trade. They sell refurbished devices and if they can't sell it they can at least get some raw materials back.
 
I see .. good policy .. just does it mean, some hardwares of new apple devices can be secondhand?
 
@Shafizadeh No, Apple has a separate shop for refurbished devices. apple.com/shop/refurbished
And the refurbished devices are cheaper for obvious reasons.
 
ah ok .. got it
 
1:25 PM
Mistake in explaining function operation ・ Documentation problem ・ #80035
 
@kooldev What does Fiber::poll() do exactly?
@kooldev resume() and throw() were private, just on there to show what the registered callback would do.
All that's really needed for the public API is Awaitable::onResolve() and Fiber::await().
I'm not sure about Continuation instead of a callback, I'd have to give that some thought. Curious what @bwoebi and @kelunik think.
 
1:46 PM
My initial impression is that the Continuation object is unnecessary and would just add more overhead to each context switch.
 
1:57 PM
@StatikStasis \o/ :D
 
@IluTov Good morning!
 
2:37 PM
Are you around?
 
2:47 PM
Yes, twirling around on my chair
 
Not you, @IluTov. :-P
 
3:16 PM
@Crell but he's "around"
In circles :D
@Derick are you dizzy?
Unrelated, building a server to be secure from the start makes me happy
 
0
Q: how to make sure implicit OpenId implicit flow works In Couchbase Sync Gateway

zohrehhi I am using identityserver4 in backend for getting jwt token inside of my app I want send my token to syncgateway and take a sessionid I read this article https://docs.couchbase.com/sync-gateway/current/authentication.html#implicit-flow and i am using OpenID Connect implisit flow but I have thi...

 
Anyone want to weigh in on the two outstanding naming-things questions here? github.com/php/php-src/pull/6046 - I'm fixing tests and don't want to have to change things several times. :-)
 
3:37 PM
@Tiffany what's the point of a server if it's unplugged?
 
3:57 PM
Door jam
 
4:20 PM
@BogdanUngureanu you could ask @Sjon about how to self-host 3val.
 
@Danack sorry, are you available where I can discuss on whereby with you?
 
I'll be online later. Need to get fresh air.
 
thanks 👍
 
@zohreh If this ( Athurazation Breare ) is how it is written in request header, it could be reason why doesn't work.
 
@Crell Kind of, I might not write back immediately but hit me with your ideas 😁
 
4:33 PM
Hi there. I'm working on a more detailed work through but here's the elevator pitch.
 
obviously very simplistic, but just sort-of enough code to provide a halfway functional thing
 
1) We want pattern matching and destructuring for enums/ADTs in match().
2) We also need a way to use it outside of match().
3) The "let" syntax is kind of verbose.
4) match() is already written to not use pattern matching, so we have to account for that, and auto-detecting things is hard and error prone.
5) PHP is running out of sigils. :-)

So... I propose we add the walrus.

[pattern] := $var // returns boolean and potentially assigns to vars in [pattern].

And then in a match arm, => means "test with ===", and :=> means "pattern match, and if returns true use the rhs expression."
Only applicable for arrays and enums for now, but at least in theory could be extended to other types.
 
@bwoebi Seems to be a much more complicated and confusing approach vs. the simple API I suggested.
 
@Trowski Well, the API is just the first file
 
@Danack thanks but I don't think @Sjon is willing to share it :)
 
4:41 PM
@Trowski with your API … where does it jump to when we call await()?
as in: when does it go back to the event loop so that we can poll for new events?
@Trowski What happens when there's no other awaitable ready?
Your API sort of implies that there's an event loop behind the Fiber interface, to me
 
@Crell I'm afraid that syntax isn't possible because it requires arbitrary lookahead...
 
@bwoebi Yes, it does. I was thinking the main context would be a fiber, but my API probably needs a Fiber::run(callable $cb), where-in any Fiber::await() call would reside.
In Amp, Loop::run() would probably call Fiber::run().
 
the main context can be a fiber, I see no issue with that
 
I like the idea that pattern matching is an expression that returns a boolean. I'll definitely have to give that some more thought.
 
@bwoebi Ok, then we probably just need to define a Fiber::poll(callable $cb) that tells the event loop we ran out of things to do, so poll sockets, etc. (Which now I understand what poll did in your gist @kooldev)
 
4:50 PM
@Trowski I think you should make Fiber implements Awaitable then
 
With my proposed API, Fiber objects wouldn't really exist (from a public API perspective, they would exist internally)
Fiber::await() could just be a function too…
Being a static function, obviously it is… was more just a name really.
 
@Trowski yeah exactly, I don't particularly like that… it has strong ties to promises and event loops
 
It doesn't have to be an event loop though
 
With my API suggestion we have full control of fibers and can just jump around as it fits our needs
@Trowski the poll() is sort of an event loop call :-D
 
Sort of, but you need something to resume fibers, call it what you will.
In your example, Fiber::continue I guess should really be Fiber::send and Fiber::throw?
 
4:55 PM
@Trowski can do that as well, instead of dynamic properties
would have same result
 
I don't like how any function wanting to pause a fiber has to understand how the scheduler works.
 
@Trowski it doesn't … as said, you can just use promises & deferreds
> // just to show off direct fiber interaction, can obviously also do delay(): Promise and return null in the callback, resolving a deferred instead
@Trowski you can always just call await(new Delayed(100)); as well
Thinking about it @Trowski your API suggestion has one clear advantage, that is, if we integrate it in internals, they can just internally create an awaitable and await that one for blocking ops - if we want to ever integrate that
Also @Trowski we do not need poll(), when await() has nothing to do, it can just jump backwards, as in, we call resolve() which leads to a fiber being continued, and when that fiber awaits again, the location where resolve() has been called gets picked up again
 
@bwoebi That was a huge aspect I was looking at – my API provides a clear path to using async/await.
 
It just has sort of the disadvantage that you do not get to control continuation depth (?)
or maybe you can control that within resolve() itself instead of within the Fiber
 
@bwoebi It probably needs to know where to go to do whatever is necessary to call resume on active fibers.
As you said, where does it jump to if all fibers are paused?
 
5:06 PM
@Trowski back to the original place which resumed the very first fiber
which presumably is within the event loop
 
@bwoebi Right, it should be. Unless you called Fiber::await() within the main fiber, but then the program can just end (because that shouldn't happen).
Though that means we need some way to initialize a new fiber context.
 
@Trowski we need that anyway?!
to run two things in parallel
like async(function() { ... })
 
Yeah, so we need Fiber::start(callable $cb, ...$args)
I forgot about that in my API.
Was thinking too linearly.
 
which is why I meant Fiber should implement Awaitable
 
Yep, now I get it. Will update my gist.
 
5:13 PM
and when you do the first await() within a Fiber::start(), it should continue the code after the Fiber::start()
@Trowski may I suggest just offering two functions await(Awaitable) and async(callable)? :-)
no Fiber namespace or such
 
@bwoebi Yep, makes sense. Essentially like $coroutine = new Coroutine($generatorFn());
@bwoebi I guess async would return an instance of Fiber, though that would mostly be an implementation detail, as async would be just documented as returning an Awaitable.
 
@Trowski correct
 
@Trowski what's that \u001b at the start of your message :-D
As in, how the fuck did you type a literal escape character :-D
 
@bwoebi I have no idea how I did it… I edited it, is it still there?
 
5:23 PM
yes
 
Some weird thing my browser must have done then. I did hit escape at some point.
 
lol
 
@bwoebi So does that make more sense? Is that better than just having a Fiber clas with yield() (or suspend()), start(), resume(), and throw()?
 
@Trowski well… it's hard to compare, depends on your goals. If we want something easily usable in event loop contexts, sure.
 
Which IMO is pretty much the whole point of Fibers.
 
5:30 PM
If you want to do computations in parallel, then the other API (cooperative preempting) will be easier to manage
to jump back and forth
If you want to do somthing when available, then this API is better
and our goal is the latter … so … :-)
 
Though for inclusion into PHP, what would be more likely excepted?
 
for inclusion in PHP the latter one is what we want, to allow for internal migration
As said, I want to see your API suggestion implemented
 
I'd jump right on it if I had any clue how to do it. :-D
@bwoebi Hopefully you or @kooldev can tackle that portion.
 
5:55 PM
@BogdanUngureanu well, I can tell you how I self-host 3v4l ;)
 
@IluTov ... <expletive deleted>
 
curl slack.com/api/chat.postMessage —``token xoxp-abc... —``body ...
what does " —``token xoxp-abc... —``body ..." this part mean ?
 
@Crell what is the matching syntax? If we can integrate it e.g. in the existing array dereference syntax (when building the AST) and only check at compile time, it may work out
 
@bwoebi can you help me out? This is the first time I am trying to use an API and I dont know curl
 
6:13 PM
@user123456789 don't ping random people, if someone is able and willing to help, they'll respond to you.
 
@Crell Well, thanks to researching alternative attribute syntaxes I now know of various unambiguous start symbols xD I'll think about a few things. Also, not all patterns are ambiguous so we could definitely only require a prefix for those that are.
 
@user123456789 unless the person is someone who's already familiar with you and have contacted in the past. I may have jumped the gun on that, so my apologies if I'm wrong.
 
No problem, I don't know him. Didn't read the chat guidelines
 
7:02 PM
@bwoebi What I had been noodling with is:

['age' => $age, 'name' => 'Juan'] := $assoc; // Returns false, OR returns true and sets $age = $assoc['age'];
And then for match, :=> to trigger pattern matching rather than === matching.
For Enums, then, Optional::Some($x) :=> $y; // if $y is an instance of Optional::Sum, extract its first associated value to $x and return true.
But if the infix doesn't work, we need something else. Poopy.
 
@Crell well, that's normal array syntax, that can be trivially parsed
 
@IluTov just said it requires too much lookahead.
 
no, we need to parse it as array
 
@bwoebi Yeah but array shapes aren't the only patterns we want
 
@IluTov which ones do we want as well
I.e. will [...] be the common delimiting?
 
7:05 PM
At least array and enum.
 
It's mostly about ADTs, so something like Option::Some($value) which yeah I guess we could also be parsed as a method call.
 
@IluTov yes, that would be a static method call
we need to parse that on the AST level then
I wonder … whether we should have lexer -> parser -> logical token tree -> AST
 
@bwoebi I never followed the discussion, what's the downside of allowing arbitrary lookahead? Just performance?
 
where the logical token tree is sort of an early version of what's parsed, but without grammar restrictions
but already nested
and in the AST we would then have proper ENUM_ADT identifiers or such
 
@bwoebi github.com/php/php-src/compare/… This is a pattern matching POC I created a while back. The tests should give you a feeling of what I had in mind.
Syntax is heavily inspired by Rust. You can find it's grammar here: doc.rust-lang.org/reference/patterns.html
 
7:18 PM
I think I have a decent handle on enums, but pattern matching to get data back out is the big hole right now. If we can figure out what that looks like I should be able to wrangle enum syntax into something nice and user friendly.
 
@bwoebi What this is kinda missing is that we're planning to allow patterns in different places. For example, you could allow pattern matching in if statements, in loops, and in standalone assignments that throw if the pattern doesn't match.
 
@IluTov syntax example?
 
See my sample from above, modulo := not being viable.
 
let Option::Some($x) = $y;
// Throws if $y is Option::None
if (let Option::Some($x) = $y) {
    // Only executed when $y is Option::Some
}
I don't think we can really disambiguate here without a prefix.
 
why is let necessary?
can't we just use bare assign?
currently only variable-like exprs are allowed on the rhs
 
7:24 PM
@bwoebi I guess technically we can. But to me that would kinda look like an assignment to a reference (although that's currently not valid syntax I think)
 
Making = sometimes mean assign, and sometimes mean pattern match strikes me as confusing both for the parser and for the reader. Hence why I was looking for an alternative.
Or... What about <- ? :-)
Option::Some($x) <- $y
Though I suppose that still has the same lookahead problem, plus I don't know how that works in match().
 
@Crell that's particularly problematic because of unary minus
@Crell Don't distinguish assign and pattern match, but consider it: make lhs equal to rhs, by updating the variables on the lhs
$x = $y < $x is equal to $y after assign
 
Hrm. That doesn't offer a potential for expansion to non-equality checks, does it?
 
@Crell like?
 
(Which may or may not be needed, I don't know.)
 
7:31 PM
@bwoebi Yeah, Rust assignments all just accept patterns on the lhs, there's no other type of assignment. It also has downsides though. A variable on the lhs of a match arm might not do what you expect.
 
@IluTov example?
 
match x {
    y => ...,
}
@bwoebi When do you expect this to match?
 
I think we should just have = - must always succeed, else throws. :=, returns boolean on failure
 
If I understand Python's new pattern syntax, you can do things like

match foo:
case foo < 5:
...
Rust has some weirdness under the hood, which is both very weird and where its power comes from. :-)
 
let x = 1;
let y = 2;
match x {
    y => ...,
}
Would've been a better example :)
@Crell Why do you have to repeat foo?
 
7:35 PM
I may have the syntax wrong.
match value:
    case [*v, label := (Promise() | str())] if v:
        value = tuple(v)
    case _:
        label = key.replace('_', ' ').title()
 
@Crell That looks very confusing to me :D
 
It's a straight copy from the PEP proposal. :-)
bbiab. But I think fundamentally we need some syntax that doesn't look like assignment to indicate extraction. Making it the same syntax is just going to be very confusing, both for the engine and the reader.
 
@IluTov In match I expect the current match rules to persist - if you want to get the value … maybe add a token, like &$x
match ($a) { Optional::Some(&$x) => ...; }
otherwise I'd expect it to match a some whose value is equal to $x
 
@bwoebi Not sure & is appropriate here, maybe something like var?
 
No idea yet what's the best token there
 
7:42 PM
Or even something completely different like bash-style >$x, indicating data is flowing into it?
 
but should be some token prefixed
 
> as a unary prefix should be unambiguous
 
yeah, > would work, yes
 
[$a, $b, >$c] = $var;
If we didn't have array destructuring already that would work nicely...
 
@IluTov what would that even mean? some destructured and some not?
or would that be an assertion on the other array elements?
 
7:53 PM
@bwoebi Exactly
[1, 2, >$c] = $var;
Kind of like that, just with the value coming from a variable.
 
I don't think that would be that valuable
 
And if the values don't match it would throw.
@bwoebi Maybe not, I mostly just don't like the plain variable without any sign of it being assigned in match.
 
@IluTov In match all assigns should be marked
 
@bwoebi But then we'd keep it consistent and do it everywhere, no?
 
hm
would be nice but
 
7:57 PM
// Why is > required here
match ($y) {
    Option::Some(>$x) => ...,
}
// But not here
if (Option::Some($x) = $y) {}
I think that would be kinda confusing.
 
@IluTov the ship on prefixless destructuring has sailed
You'd need something like the let prefix you mentioned in the match discussion thread
 
@NikiC Yeah, @bwoebi suggested disambiguating after parsing.
 
No way that is going to work in any sensible way
 
8:12 PM
If only the match keyword weren't already used... :-)
 
@NikiC It could work, we'd have to traverse the lhs of assignments and match conditions to make sure the expression is a valid pattern and then change the type of the ast nodes. Not sure what the performance implications are here. Could also be a pain in the ass for external tooling (like php-parser). Not sure it's a feasible idea.
@Crell It doesn't really change anything. We'd still have the same problem outside of match.
 
I mean "match" as a prefix to indicate "this is a pattern match extraction thingie."
 
@Crell Well, let is shorter than match and you still thought it was too verbose :P
 
But it sounds like we need either:
1) A pattern syntax that cannot be mistaken for anything else in the language.
2) A prefix of some kind to indicate "this next thing is a pattern, not whatever it would look like otherwise."

An infix distinguisher like := is not going to work, I guess.
We are fast running out of sigils...
 
@Crell Yeah, I think infix disambiguation is not possible unless we touch the AST after parsing or we change the parser to do lookahead. @NikiC Why again wasn't that feasible? I know it was discussed for arrow functions but I don't remember the reason.
@Crell We actually have quite a few, |, *, >, % are all valid (I think there are a few more). Not sure which one would make the most sense.
 
8:19 PM
/me will noodle.
Would we want a prefix, or a wrapper?
(Not to repeat the attribute syntax battle...)
 
@Crell No wrapper please :D
 
Like:
% Optional::Some($x) = $maybe

%( Optional::Some($x) = $maybe )
 
@IluTov Depends on what kind of lookahead you mean
lexer lookahead is a big mess, because you replicate the parser in the lexer
parser lookahead we can support via GLR, but we'd want it to be a guaranteed linear split
For arrow functions iirc there was the potential for exponential complexity when considering some future language extensions (like arbitrary defaults)
In this case though, I really don't think it's a parsing problem. There's simply a fundamental ambiguity between values and patterns. I don't think having some kind of marker somewhere is avoidable.
 
Absolutely crazy question: Would it even be possible to do what Rust does and make assignment a special case of pattern matching, as Ilja describes?
 
@NikiC I see. Yeah A simple marker like > or * at the start of the pattern would be enough. I would've liked ~ (as in is roughly equal to) but it's already a unary op.
@Crell Not sure. Even if we do that, the ambiguity in match remains (is $foo in the lhs a pattern or an expression?).
So if we require a prefix there, why not just require it everywhere and avoid the headache?
 
8:29 PM
If it's a single variable then they degenerate to the same thing.
 
@Crell I bet you that's not what most people expect.
$x = 1;
$y = 2;
match ($x) {
    $y => var_dump($y),
};
 
Hrm.
 
If we interpreted $y as a pattern (which we can't anyway because that would be a BC break) the pattern would always match and assign the value to $y.
Rust does that and I think it's kind of confusing. Swift requires a prefix (let) to denote you're actually declaring a variable.
 
Question: I am quite sure if we allow matching on arrays and enums, someone is going to ask for matching on arbitrary objects. Is that something we even want to consider, before I experiment with ways of doing that, syntactically?
(It's sort of the generalized case of enum matching; where enums would have a stock default match logic.)
 
@Crell Depends on how we implement enums. With sealed classes we could actually do something like that: github.com/php/php-src/compare/…
If we don't do enums that way it would probably still make sense to allow it but it wouldn't be quite as important I think.
 
8:38 PM
I mean without necessarily binding it to public properties.
class Employee {
    public function __construct(private string $name, private int $age, private string $title) {}

    public function __match(string $name, int $age, string $title): bool {
        // ... Something here, not sure what yet.
        return ['name' => $this->name, 'age' => $this->age];
    }
}

%Employee($name, $age, 'CEO') := $person;
 
@Crell Not sure what you mean.
 
Does that horrify you?
 
@Crell Yeah no I would definitely be against a magic __match method :) @NikiC mentioned he was working on accessors a while ago, in that case I would even say let's allow properties (or accessors) only in an object pattern.
 
Hm.
The conflation of structs and method into objects seems more and more like a mistake, 30 years on... :-)
 
Pattern matching operates on the shape of a value, I don't think there should be any user logic involved in that.
 
8:42 PM
Objects by design (in PHP) are of opaque shape. Or rather, the shape is defined by an interface, not properties. Nominally.
 
@Crell Does it? You might like C :P
 
Burn it with fire.
 
@Crell Well, normally patterns are validated at compile time, we don't really have that option.
 
Would pattern matching be at all meaningful on other primitives? Ints and strings?
 
@Crell Yes.
match ($point) {
    >[0, $y] => ...,
    >[$x, 0] => ...,
    >[$x, $y] => ...,
};
Silly example, but you get the point.
Pun not intended ^^
 
8:51 PM
:-)
But $point in that case isn't an int, no?
 
@Crell No, but $x and $y are patterns and matched against the values of the given array elements. 0 is also a pattern matched against the array element.
 
I mean more like this:

$i = 5;
% 0 < $x := $i;

^^ Is that even a thing?
 
@Crell Not sure what that means ^^
 
Neither am I, that's the point. :-)
I mean, does it make sense for the RHS to be an int or string? It makes sense for an array, enum, or maybe object, since those are product types. But I don't know if it makes sense for a primitive.
 
@Crell Ints, for ranges yes.
 
8:56 PM
So the above would be "assign $x = $i iff $i is greater than 0".
 
match ($int) {
    *0..<100 => ...,
    *100..<200 => ...,
};
(or whatever prefix)
@Crell Not sure about that. The lhs doesn't usually look like a condition. It describes what the given value should look like for the pattern to match.
 
%{0 < $x} := $i;
%{100 > $x} := $i;
%{$x > 0, $x > 100} := $i;

This isn't impressing me...
Hrm.
 
 *$x @ >=0 = $i;
 
... For product types, we need to be able to assign on the left. But... we don't really for ints. We do for strings, however.
%{$x, 0...100} := $i;
%{$x, >0} := $i;
%{$x, <50} := $i;
 
That's closer to what you're describing but looks beyond confusing.
 
9:03 PM
// For strings
$s = 'Hello World';
%{a regex?} := $s;
%{"/Hello $subject/"} := $s;
What I'm sort of driving at is % defines a pattern literal, but you could also save that to a variable. It's just a value. Then := is the "evaluate and extract fro the rhs according to the pattern on the lhs", and if the types are incompatible then it obviously won't match and just returns false.
 
Honestly, I'm mostly unimpressed with the marginal improvements from pattern matching. I've felt the same after the POC. It's great for compiled languages. For PHP the code is sometimes a tiny bit shorter but probably harder to grasp for most users. The only really good use case are ADTs.
 
Possibly. I think it's worth thinking through all the various types they could apply to, though, if only so we can say with confidence "we tried, it doesn't work" when someone inevitably asks. :-)
 
I need to get a shower. I'll be back in a bit.
 
We certainly could say that they apply to compound types only; we just need to be able to justify the people going "but why?"
Clean coder, clean code...
 
@Crell ewwwwwwwwwwwwwww
 
9:13 PM
To which part?
 
the syntax
I've been trying to follow along with the conversation but the concept for "pattern matching" for enums has me confused. It's probably something I need to read more on when I have a clearer head.
but I really don't like that syntax :P
the bikeshedding begins
 
:-)
 
on that note, I will exit the conversation since I will likely have nothing valuable to add :P
 
The syntax is weird if you're not used to it. Honestly I had to read the Rust page on it 4 times before I understood it.
On the contrary, input from more than the engine nerds is a good thing. :-)
 
9:27 PM
@Tiffany Which part don't you follow? We could use the practice explaining things.
@IluTov @Tiffany @NikiC https://gist.github.com/Crell/58f6ca9c3cdb7f86912adca5bc389f4d

Here's my latest brainstormy sample code to tear apart.
@Tiffany Legit, I'm curious if you find it comprehensible from the description there.
 
https://wiki.php.net/todo/php80

Happening this week :)
 
9:46 PM
@Crell sorry, I'll read it later this evening or in the morning, I have company over.
 
No worries.
 
@Crell Not sure we need :=> when we already disambiguate with a start symbol.
 
Maybe. If patterns can be reused rather than just be used literally inline, we probably need it. And I think there's some value to making it clear that it's not a usual assignment.
 
@Crell I don't believe using patterns as values makes sense, especially since you're literally binding values to variables in it.
Or at least you can. I get what you're saying though, something like setPattern(0..=100) is an interesting idea. But in that case you're probably better off passing a closure.
 
Mm, good point. Though a closure wouldn't allow you to bind variables out of its own scope.
But as you can see from the link above, that already creates weirdness that is probably undesireable except for assignment-free patterns.
 
9:56 PM
@Crell What do you mean by "allow you to bind variables out of its own scope"?
 
$c = fn($arr) => %['a' = $a, 'b' => 5] := $arr;

$ret = $c($someArray);
// $a is not set here, and $ret is just true/false, so... why?
 
@Crell Oh I just meant an old, boring function () {} with a value captured by ref.
(if you want to modify something in the outer scope that is)
 
Oh. That... I suppose would work, but also be super verbose and kind of gross. :-)
 
@Crell Gross things (like capturing and modifying things in the outer scope) should be verbose :)
 
Granted...
I'm just still slightly uncomfortable with = having two meanings, even if the parser could disambiguate.
 
10:05 PM
@Crell Yeah, honestly I'm kind of second guessing the whole approach. If we made type comparison simpler (e.g. is Foo instead of the super verbose instanceof Foo) maybe it wouldn't even be necessary. If we require all ADT values to have names we could access them by name $option->some like you have suggested before I think.
 
...
Well, That would still be strictly less capable than pattern matching.
 
@Crell Well, we can already do everything without pattern matching. Pattern matching is just a little bit shorter. There were a few examples in v1 of match. wiki.php.net/rfc/match_expression#pattern_matching
 
Hrm.
With ADTs, without pattern matching how would you get at literal associated values?
Variable associated values you could say have to be accessed by their variable name, and maybe even require constructor promotion. And then implicitly make them all read-only.
But literals don't have a name.
 
@Crell $option->value It's not quite as explicit, in that case we can't really enforce you're not accessing value before proving $option is some. If Some was a normal class static analysis could help you really easily actually. If only f***ing autoloading would be possible.
 
That works when there's only one value.
 
10:14 PM
@Crell No, you'd name your ADT values
 
enum Direction {
case North('left');
}
 
enum Option {
    Some(mixed $value)
    None
}
 
You're saying instead of that you'd be forced to do:
enum Direction {
  case North(dir: 'up');
}
 
So instead of just defining a type and relying on the order you'd name your ADT values.
 
Right, if it's a dynamic name.
 
10:20 PM
I mean, technically it's possible to autoload. If the class isn't found, you'd move up one namespace and see if that class is defined (So, instead of Acme\Option\Some -> Acme\Option). Throw if that's not an enum, if it is try to find the given subclass. That would mean autoloading of enums has slightly worse performance.
Also, relying on catching undefined class exceptions would have worse performance but that seems acceptable to me.
That would be logic that needs to be implemented in Composer though.
In that case, it would actually make sense to separate ADTs and enums though.
ADTs -> Implementable tough sealed classes. Enums -> Static "singleton" types.
 
If you'd asked me in the 00's whether I'd ever say these words then I'd have laughed in your face, but I'm disappointed by the lack of Australians on the internet.
 
@DaveRandom try turning your monitor, maybe you'll see more Australians then (sorry, not sorry)
 
Other problem with not having pattern matching: How does match() know to do an instanceof rather than a ===? === is fine for a Unit member or a Literal associated value enum, but not for an ADT.
 
@bwoebi Ah you may be on to something, is there a unicode combining diacritic for "upside down"?
 
@Crell Maybe we don't need to. As you know there are plans to allow dropping (true). Then something like that would be enough:
match {
    $x is Option\Some => var_dump($x->value),
};
(or instanceof if we don't want to implement a shorter alias for that)
 
10:31 PM
...or instanceof rather than is, since we already have a perfectly good keyword
and PHP != C#
(which is a shame, in some ways)
 
@DaveRandom I've prototyped with is to also allow primitive types and union types.
Would be more coherent than instanceof which I think is good.
 
I've no issue with is tbf, as long as I could use it everywhere I can use instanceof
 
That seems more verbose than it needs to be. Especially when you've spent all this time selling me on pattern matching. :-)
 
as long as it's consistent, that's the main thing I care about
 
@IluTov If Optional::Some(5) is rendered as a static method on Optional, then the autoloader already knows what to do with it.
 
10:33 PM
@Crell Haha yeah I'm really sorry for flip flopping :)
 
Well, better to flip flop now than in 8 months. Still, though...
 
@Crell Yes, but how do you check if a value is a Some? If Some is it's own type, we'd need to separate it with a `\`, thus leading to the autoloading problem.
 
Optional::Some. You can never specify just "Some".
 
@Crell Yeah but comparing $value === Optional::Some doesn't really make sense.
 
It does for Optional::None, since that's a Unit. For Some, that's where pattern matching would be needed.
/me finds it amusing how we've swapped sides on this question now.
 
10:43 PM
@Crell Yeah, pattern matching or type checking.
@Crell Lol ^^ It's really not intentional I swear :D
I kinda think the complexity for pattern matching is way too high to be justified for one use case. I'm just trying to see if we can solve it in some other way.
 
That's me, about 4 days ago...
 
@Crell Let me speak to Jordi about the autoloading thing to see if it's viable. If it is I'll try to describe it in a short document.
 
I still don't fully grok what the problem is with autoloading.
 
Now you just forget everything I said in the last 4 days and we'll be on the same page again xD
 
:-P
 
10:54 PM
Well, the point is, if we implement ADTs through sealed classes they need to be in the same file (because how else do you restrict subclasses?) but multiple classes per file is not supported by autoloading standards.
But the only thing we really need is to trigger the autoloader again with the namespace just above. I'm not yet sure if that's viable.
 
Which is why I argue that an enum member is always and forever referenced through its enum, so the name of the enum is available and you can autoload that, which is what matters anyway.
 
@Crell Yeah, I agree about that. That's why I felt that way before too. Unfortunately I see no good way of implementing an intuitive type comparison without pattern matching. Actually, thinking about it, we could do something like $option is Option::Some (and then accessing the value through a named param).
 
Again, named params are available less than 100% of the time.
 
00:00 - 23:0023:00 - 00:00

« first day (3606 days earlier)      last day (1336 days later) »