Kipper icon indicating copy to clipboard operation
Kipper copied to clipboard

[Feature] Implement built-in Kipper types objects

Open Luna-Klatzer opened this issue 2 years ago • 0 comments

Is there an existing proposal for this?

  • [X] I have searched the existing issues

This feature does not exist in the latest version

  • [X] I am using the latest version

Proposal

Implement a new runtime type system, containing the base types (such as str, num, null etc.) implemented using objects extending a Type parent class. These base types should also be referenceable, such as num, which should return its type object if referenced using the identifier num.

This would allow the typeof function to be implemented in a way, where, unlike JavaScript, actual type objects are returned which can be used to check the type of a value. For example:

  • Getting the type of a value:

    typeof(1) // Type 'num'
    
  • Comparing the type of a value with a runtime type:

    typeof(1) == num // -> true
    

This would allow the type objects to be used as a unique way to represent runtime types, unlike JavaScript where a string is used to describe the type of a value. Furthermore, this would provide a way to go around the behaviour of JavaScript and ensure type cohesion in the type system of Kipper that is built on top of JavaScript.

This will also mean certain behaviour might be different, such as the JavaScript behaviour that makes null be considered of type "object" when checked using the JavaScript typeof operator.

Exact behaviour / changes you want

  • [ ] Implement parent class Type, which will represent a runtime type.
  • [ ] Implement runtime type objects, which will exist during runtime and can be referenced in Kipper code using their identifier.
  • [ ] Implemented new function typeof(EXP) which will return the type in the form of a type object.

Additional Notes

  • #373 (Detailed implementation reference)
  • #332 (Proof of concept for the runtime types)

Luna-Klatzer avatar Dec 07 '22 20:12 Luna-Klatzer