Skip to content

Allow omitting self type annotations in impls #82

@osa1

Description

@osa1

I think in impl methods we can always omit self types. For example, we have this in the standard library:

trait Step[t]:
    step(self: t): t

impl Step[I32]:
    step(self: I32): I32 = self + 1

Here we can infer type of self from the impl head.

Another, more complex example: (note that this trait will change when we implement associated types again)

trait Iterator[iter, item]:
    next(self: iter): Option[item]

    map(self: iter, f: Fn(item): b): Map[iter, item, b]
        Map(iter = self, f = f)

type Map[iter, a, b]: ...

impl[Iterator[iter, a]] Iterator[Map[iter, a, b], b]:
    next(self: Map[iter, a, b]): Option[b] = ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    type systemDesign of the Fir type system

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions