myst-lang / myst

A structured, dynamic, general-purpose language.
http://myst-lang.org
MIT License
118 stars 17 forks source link

Implement equality for Types #173

Closed faultyserver closed 6 years ago

faultyserver commented 6 years ago

Types do not currently implement ==, meaning any comparisons of Types in the language itself requires some conversion (generally to a string) like so:

1.0.type.to_s == "Float"

Having == defined on Type objects will clean up a lot of specs that are trying to assert type equalities, and is generally just useful for everyday programming.

TType itself already implements ==, so the Myst method can simply pass through to that for the actual comparison. This will also ensure consistency between the Myst method and its usage in the Interpreter (e.g., in Matcher).

For an example of how this method can be implemented as a passthrough, check out methods like Float#==:

https://github.com/myst-lang/myst/blob/3ec71d3039fe98f1847482681fda9797f22efaac/src/myst/interpreter/native_lib/float.cr#L54-L56