overloading
#171
Replies: 2 comments
-
Another idea for inspiration might be clojure's multi-methods. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Adjustments in #162 were in reaction to this and @samth's comments in #170 to provide a way to support definitions of a binding that span multiple top-level groups. I'm not sure about the right design point for definitions and overloading, but between the proposed/prototyped expander, binding-space, and static-information layers, I think we have a good amount of room to explore. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Given that one of the goals of Rhombus is to have extensible syntax, it stands to reason that built-in operators and functions like
+
andlength
should be extensible as well.For example (based on syntax from #163), one might wish to overload operators for a custom
Vec2
type as follows:Two paths
Static types
For
v1 + v2
to have no runtime penalty overVec2_add(v1, v2)
would require the compiler to know the types ofv1
andv2
beforehand. Guaranteeing that this happens would likely mean requiring the language have some level of static typing, which would represent a significant divergence from Racket semantics. I think taking this road can only lead to fully-fledged type system as introducing a mechanism for static overloading will leave one wanting a mechanism for generic functions, and pretty soon you'll have the whole shebang.Multiple dispatch
The alternative option - which will come with a runtime penalty in the general case - would be to use multiple dispatch (cf. Julia, Common Lisp). Specialization by the compiler could allow elision of this dispatch—keeping performance the same as in the statically-typed case—but the effectiveness of this would depend heavily on the compiler and could make performance hard to reason about. (Or, if you're feeling a bit crazy, you can just do monomorphization everywhere.)
Coherence
Presumably, two modules should not be able to provide conflicting overloads for a function foreign to both of them (cf. Rust). I'm not sure if this is a hard problem.
Pattern Matching
It may be worth exploring if a single general matching mechanism could cover function overloading as described above as well as defining functions using pattern matching such as
Beta Was this translation helpful? Give feedback.
All reactions