Skip to content

[Feature Request] Support explicit syntax for partial parameter binding of Self #4337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 task done
soraros opened this issue Apr 12, 2025 · 2 comments
Open
1 task done
Labels
enhancement New feature or request max-repo mojo Issues that are related to mojo

Comments

@soraros
Copy link
Contributor

soraros commented Apr 12, 2025

Review Mojo's priorities

What is your request?

As title. Instead of this:

struct Pointer[
  T: AnyType,
  origin: Origin,
  address_space: AddressSpace,
]:
  alias _with_origin = Pointer[T, _, address_space]

  fn __init__(
    other: Self._with_origin[_],
    out self: Self._with_origin[_immutable_cast[other.origin].result],
  ):
    ...

I want to write:

struct Pointer[
  T: AnyType,
  origin: Origin,
  address_space: AddressSpace,
]:
  fn __init__(
    other: Self[origin=_],  # unbinding
    out self: Self[origin=_immutable_cast[other.origin].result],  # rebinding
  ):
    ...

What is your motivation for this change?

  • It's useful.
  • This behaviour is consistent with other type aliases.
  • It avoids the need to create ad-hoc names that don't make much sense.

Any other details?

As an added benefit, we get Float64[width=4] etc, which is also vastly useful.

Related: #1904.

@soraros soraros added enhancement New feature or request max-repo mojo Issues that are related to mojo labels Apr 12, 2025
@owenhilyard
Copy link
Contributor

I like this train of thought, but I think we need a way to also do parameter kwargs.

@soraros
Copy link
Contributor Author

soraros commented Apr 14, 2025

As an example, #3083 would look much cleaner with this feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request max-repo mojo Issues that are related to mojo
Projects
None yet
Development

No branches or pull requests

2 participants