Skip to content

Enums with methods #34

Description

@NightmarePog

Enums can currently hold data in their variants but can't define methods. If you want behavior tied to an enum, you have to write a free function and match on it externally — which scatters logic that logically belongs together.

Being able to write:

```
enum Shape {
Circle(radius: float)
Rect(w: float, h: float)

area(): float {
    match self {
        Circle(r)  => 3.14159 * r * r
        Rect(w, h) => w * h
    }
}

}
```

...and call `shape.area()` would make enums significantly more useful as a modeling tool.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions