Type variable binding would be difficult in Dart, I guess. For instance, we
have to be careful.
is Y".
are very loose..
Post by 'Burak Emir' via Dart Misc* I'd keep the 'case' in match expressions. Consider i.e. exp match { case
x => (y) => z case 1 => 2 case _ => ... } without the 'case'.
* exhaustiveness checking for testing subtypes works if you can assume a
closed world (e.g. knowledge of all subtypes).
In Java, Scala, ML, things like separate compilation or dynamic
class-loading break that assumption, so Scala introduced a keyword "sealed"
that would forbid subtypes other than the ones known. I'm not sure what the
plan is for dart.
* there are also situations where exhaustiveness checking may be
undesirable; for instance one may define classes that represent a rich set
of operators of propositional logic, but then after some point, they all
get translated to some subset (say NOT and AND). Another example is
abstract syntax tree classes in compilers where earlier passes translate
away / desugar constructs into simpler ones. Finally, extending an enum
with a new value, that can only appear in a certain place. Consequently, it
would be good to have a way to suppress the warning.
* about the added value of extractors aka "unapply" methods. These give
users an easy way to define their own patterns *and give them a name*,
hence it does not make much sense to compare it with object destructuring.
E.g. consider the following, with suitable SELECT, FROM and WHERE
foo(String queryString) => queryString match { case SELECT(x, FROM(y,
WHERE, condition))) => ... }
or a network protocol's pattern like: byteIterable match { case
MESSAGE(header, payLoadSize, payLoadBytes) => }
* exaustiveness checking won't easily be extended to extractors, though.
* The DEP makes me curious: what happens if one wants to match against
generic types? Would you support type variable binding or type variable
checking in addition to variable binding?
<T> foo(x) => x match { case y is List<T> => new Set<T>..addAll(y) }
* one thing that is frequently found in match statements is the ability to
match against variables declared in scope. So with a suitable extractor
"twice", we may want to check that y is 2*x, however we need a way to
reference a variable (instead of declaring a new variable x). In Scala,
variables from outside had to be capitalized, i.e.
foo(String X) => (y) => y match { case twice(X) => /* we now know that y
== 2 * X */ }
cheers,
Burak
On Tue, Nov 24, 2015 at 2:00 PM, 'Erik Ernst' via Dart Misc <
Post by 'Erik Ernst' via Dart MiscPost by Rasmus EnemanI updated it now to be a syntax error, as you said it's simple to do
anyway, no need to complicate the spec or expectations on behavior.
One pattern I'm still unsure about though is Point {x, y: x} where the
second x is clearly not being declared, should that be allowed?
That's probably just as unmanageable as the equality constraints. In the
general case, this allows us to require that, say, the left and right
subtree of a `Tree` node must be equal to each other (just use `Tree`
rather than `Point`). That might be defined in terms of structural
equality, which would entail a traversal and comparison of arbitrarily
large structures which might be overlapping and/or cyclic. Just think about
var t = new Tree(new Tree(t, t), t);
(ignoring that we'd need spell it out as a couple of statements involving
a destructive update in order to actually create such a cyclic structure).
That tree has identical "infinite" (that is, cyclic) right and left
subtrees, but since the right subtree is always returning to the top level
one step faster than the left subtree, it gets tricky to know when we can
stop and say "true", respectively how we can avoid going into an infinite
loop. We should leave that kind of traversal/checking to the domain
programmer, not the language.
Post by Rasmus EnemanIt's still easy to do with a guard but it might be expected that it
would be allow because that difference of literal and variable is never done
anywhere else in the language.
One other thing is p as Point {x, y} which you have used as a pattern
above. As currently written it is not allowed, but could be easily added.
I have no opinion on either but I think that it might be unnecessary as
in most cases you would have the object being matched in a variable
that is in scope anyway.
I also added initial wording on warnings. There probably should be more
but it's a start at least.
I think Scalas extractor objects needs to be mentioned. Personally I
don't see much of a value with them when there are object destructuring
but there are probably other opinions out there. But all classes that
would use them should be able to add getters for those values instead.
match (x) {
Some {value} => print('got $value');
None {} => print("it's empty");
}
On Wed, Nov 18, 2015 at 6:07 PM, 'Bob Nystrom' via Dart Misc <
Post by 'Bob Nystrom' via Dart MiscOn Mon, Nov 16, 2015 at 5:54 AM, 'Paul Brauner' via Dart Misc <
I agree, non-linear patterns are a gadget in my opinion. They are
superseded by guards, which don't force you to bake one particular notion
of equality into the semantics of the language.
+1.
The simplest, safest option is to have it be a syntax error for a
variable to appear twice in the same pattern. I don't think allowing
repetition there adds much value (like Paul says, you can always just guard
on equality) and I think it adds a lot of complexity.
It also makes patterns work less like variable declarations, which I
think is generally a bad idea. Variable declarations basically *are* patterns
(or a special subset of them) so I think we should encourage them to
converge as much as possible.
Cheers!
â bob
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to
http://www.dartbug.com/new
---
You received this message because you are subscribed to a topic in the
Google Groups "Dart Misc" group.
To unsubscribe from this topic, visit
https://groups.google.com/a/dartlang.org/d/topic/misc/MJXLjFxZu0A/unsubscribe
.
To unsubscribe from this group and all its topics, send an email to
--
Rasmus Eneman
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to
http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google
Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send
--
Erik Ernst - Google Danmark ApS
Skt Petri Passage 5, 2 sal, 1165 KÞbenhavn K, Denmark
CVR no. 28866984
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups
"Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
---
You received this message because you are subscribed to the Google Groups
"Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an
CVR no. 28866984