Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple dispatch for operators #2249

Closed
DartBot opened this issue Mar 21, 2012 · 3 comments
Closed

Support multiple dispatch for operators #2249

DartBot opened this issue Mar 21, 2012 · 3 comments
Assignees
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-not-planned Closed as we don't intend to take action on the reported issue type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented Mar 21, 2012

This issue was originally filed by Sebastian.Por...@gmail.com


Math in 3D graphics at the moment requires a complex API for different object types. Adding multiple dispatch at least for overloaded operators would solve this problem.

example code:
mat4 M1 = new Mat4();
mat4 M2 = new Mat4();
vec4 V1 = new Vec4();

M1M2 and M1V1 should be handled with different functions and return different object types. Currently both would be handled by the operator+ in Mat4 class. It is required to either detect object type on runtime and pass it to the correct function or to ignore operators completely and fallback to JS-like:
multiplyMat4Mat4(M1,M2);
// and
multiplyMat4Vec4(M1,V1);

It's certainly possible to replicate multiple dispatch in JS by generating different function names during compilation. It would require an additional runtime detection (the same that would make current operators more useful).

As a game developer I often have a hard time with JS, I would be very happy to see that Dart solves such problems (as it does in many other situations).

@floitschG
Copy link
Contributor

I don't think that we will support method/operator overloading, but there are two ways something similar could be implemented:

  1. double-dispatch (which would already work now). This approach is the most flexible and should work great in this context. It adds some boiler-plate, though.
  2. pattern matching switching on the operand-type (issue Add pattern matching support #35, issue Destructuring Assignment #75).

Marking as Enhancement request and assigning to Language-area, so that Gilad can make the final call.


Removed Type-Defect label.
Added Type-Enhancement, Area-Language, Triaged labels.

@munificent
Copy link
Member

For what it's worth, I'd really like the double dispatch pattern supported too. I've defined Vector types in Dart (mainly for games), and not being able to symmetrically support scalar operators on them is annoying sometimes.

@gbracha
Copy link
Contributor

gbracha commented Apr 12, 2012

Multiple dispatch is problematic from a modularity point of view. It requires a closed world assumption. It adds significant complexity to the implementation as well. I don't expect to support this.


Set owner to @gbracha.
Added WontFix label.

@DartBot DartBot added Type-Enhancement area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels Apr 12, 2012
@kevmoo kevmoo added closed-not-planned Closed as we don't intend to take action on the reported issue type-enhancement A request for a change that isn't a bug and removed resolution-wont_fix labels Mar 1, 2016
copybara-service bot pushed a commit that referenced this issue Oct 17, 2023
Revisions updated by `dart tools/rev_sdk_deps.dart`.

file (https://github.com/google/file.dart/compare/a18ad1c..7418131):
  7418131  2023-10-11  Parker Lougheed  Remove now unnecessary glob dependency override (#226)

http (https://github.com/dart-lang/http/compare/88ec75e..7240d0a):
  7240d0a  2023-10-11  Brian Quinlan  Remove obsolete pigeon-generated file (#1032)
  827f4fe  2023-10-10  Brian Quinlan  Prepare to release cronet 0.4.0 (#1031)

native (https://github.com/dart-lang/native/compare/22f4481..757f503):
  757f503  2023-10-16  Gabriel Terwesten  Use `Logger.detached` for test loggers (#158)

sse (https://github.com/dart-lang/sse/compare/e190744..37df57d):
  37df57d  2023-10-13  Kevin Moore  Enable and fix latest lints (#91)

test (https://github.com/dart-lang/test/compare/4341470..ba050ae):
  ba050ae2  2023-10-13  Nate Bosch  Move functions to non-deprecated library (#2120)
  96e1ed2d  2023-10-13  Nate Bosch  Remove unused href field from error report (#2118)
  ae7f30e9  2023-10-13  Nate Bosch  Make compiler optional in calls to currentPlatform (#2117)

tools (https://github.com/dart-lang/tools/compare/92c5c15..ddeccf6):
  ddeccf6  2023-10-10  Elias Yishak  Handling malformed log items in log file (#175)

webdev (https://github.com/dart-lang/webdev/compare/7c2c2d7..8d48d5e):
  8d48d5ea  2023-10-13  Ben Konyi  Bump package:vm_service to ^12.0.0 (#2248)
  9102b427  2023-10-13  Anna Gringauze  Add evaluation test to webdev to catch issues with runtime debugging API (#2250)
  63c7e728  2023-10-12  Elliott Brooks  Cider expects messages from a Chrome extension to be a JS object, not a string (#2249)
  a10bf10e  2023-10-11  Devon Carew  regenerate from the latest package:mono_repo (#2247)

Change-Id: I5c16c1387b613d1e6076579b26e6b64735097b7e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/330662
Auto-Submit: Devon Carew <devoncarew@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-not-planned Closed as we don't intend to take action on the reported issue type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

5 participants