Skip to content
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

Add Clone trait for builtin #1425

Open
FlammeShadow opened this issue Jan 4, 2025 · 3 comments
Open

Add Clone trait for builtin #1425

FlammeShadow opened this issue Jan 4, 2025 · 3 comments

Comments

@FlammeShadow
Copy link
Contributor

FlammeShadow commented Jan 4, 2025

Different methods to clone a object like deep_clone, copy and clone have existed in the standard library. However, without Clone trait, we can't really implement a "deep_clone" method. I think we need a unified trait to clone various objects (like Rust's Clone).

@illusory0x0
Copy link
Contributor

illusory0x0 commented Jan 7, 2025

I think we also need copy trait

@FlammeShadow
Copy link
Contributor Author

FlammeShadow commented Jan 7, 2025

I think we also need copy trait

You mean a trait like Rust's Copy?

@illusory0x0
Copy link
Contributor

I think we also need copy trait

You mean a trait like Rust's Copy?

element type is Immutable, we can use copy method rather than DFS or traverse data structure
this copy is Array::copy in moonbit.

impl[T : Clone] Clone for Array[T] with clone(self) {
  match T::mutability() {
    Mutable => self.map(T::clone)
    Immutable => self.copy()
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants