Comments (2)
With #29 and #31 done, I think it makes sense to think whether it's possible to increase the consistency of ===
and ==
:
The problem I see is that ===
can be used everywhere, including in generic contexts, while ==
requires Equals
.
I am concerned that this (slight) convenience could make users use ===
in cases where ==
would be correct.
A rather brute approach would be:
- Give
===
its own trait (e. g. Identity) that is implemented for every type and cannot be defined by a user. - In addition to
Equals
being defined for non-reference types, automatically derive==
(Equals) for all reference types according to the following rules:- Equality would be based on calling
==
on all fields of a class, similar to Scala's case classes, Kotlin's data classes, C#'s record types and Java's proposed record classes. - To avoid the problems immediately cropping up with sub-classing, sub-classing would be discarded altogether, leaving only traits for polymorphism.
- If a class implements
Equals
explicitly, this definition will be used and no equality operation would be derived. - Introduce annotations to let users
- opt out of equality, e. g.
@noEquals class Foo(let x: int) {}
, or - adjust how equality is derived, e. g.
class Foo(let x: int, @ignoreForEquals let y: int) {}
would only usex
to derive equality
- opt out of equality, e. g.
- If a class A contains a field of type B which does not support equality (the user has annotated the class B with
@noEquals
) then an error is reported, which can be fixed by:- adding
@noEquals
to A - ignoring the field with
@ignoreForEquals
- adding
- Equality would be based on calling
- In the future if something like lambdas or function types were added, they would either:
- not implement
Equals
, or - implement
Equals
in terms ofIdentity
- not implement
What do you think, @dinfuehr?
from dora.
I think this can be closed as fixed; I'll file issues/questions that arise from e. g. value types, code generation desires, or meta programming topics when we cross that particular bridge.
from dora.
Related Issues (20)
- Unified Condition Expressions HOT 1
- panic: enum value and `is` HOT 3
- Extending the reach of enums HOT 1
- `toStringHex` and `toStringBinary` strip off leading zeros HOT 1
- Consider turning asserts in @test annotated methods into soft asserts
- Allow defining and calling methods without parentheses
- `--emit-ast` doesn't do anything HOT 2
- The JIT implementation of dora is very cool HOT 1
- reinstate class syntax
- replace `fn` keyword with `fun` keyword
- reinstate `=` for function definition
- implement named parameters
- implement string hash caching
- implement definitional enums
- implement modules (singletons and holders of static functions)
- remove unary operators
- remove bitshift operators
- implement unified condition expressions
- replace procedure syntax with functions having return type `Unit` HOT 1
- How lazy compilation is protected in case of multiple threads? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dora.