Skip to content
This repository was archived by the owner on Jun 13, 2020. It is now read-only.
This repository was archived by the owner on Jun 13, 2020. It is now read-only.

Allowing functions on primitives #716

@felixangell

Description

@felixangell

We were discussing this on the IRC, and me and sorta @kiljacken both agree that they could be really convenient. For instance in the string library, to compare a string the code is:

func compare(a: string, b: string) -> bool;

Which is used as follows:

compare(foo, bar);

This is okay, but it would be much cleaner to allow for having methods on primitive types for cleaner, flexible code:

func (a: string) compare(b: string) -> bool;

Which is used as:

foo.compare(bar);

There are some obvious flaws, most of which are relevant to the module system. Another thing I could picture being quite... strange is the following would technically be valid:

"foo".compare("bar");

Though we could disallow this behaviour with literals? I'm not sure about any other flaws, but if this feature is useful, then perhaps we could discuss either why it should not be implemented, or perhaps how we would resolve these flaws (without making huge changes to the compiler or language).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions