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

Dependent default types #4452

Open
tetotechy opened this issue Sep 24, 2023 · 4 comments
Open

Dependent default types #4452

tetotechy opened this issue Sep 24, 2023 · 4 comments
Labels
help wanted Extra attention is needed needs investigation This needs to be looked into before its "ready for work"

Comments

@tetotechy
Copy link

I also have a question about the possibility of using default types referencing other generic types in the same object. This code won't compile.

The rest of the code apparently is fine, as explicitly associating the type in the function body shows.

Thanks!

@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Sep 24, 2023
@SeanTAllen
Copy link
Member

This isn't an actionable bug. In keeping with our getting help documentation, please ask "how do I" questions in the Zulip.

@SeanTAllen
Copy link
Member

Closing

@ponylang-main ponylang-main removed the discuss during sync Should be discussed during an upcoming sync label Sep 24, 2023
@tetotechy
Copy link
Author

Apologies for not making myself clear. What I meant is that the following code compiles (I changed the example a bit):

actor Main
  new create(env: Env) =>
    Foo[U8, Array[U8]](env, 10)(3)
  

class Foo[T: Stringable val, Arr: Seq[T] ref = Array[T]]
  let _env: Env
  var arr: Arr = Arr
  
  new create(env: Env, v: T) =>
    _env = env
    arr.push(v)
    
  fun ref apply(v: T) =>
    arr.push(v)
    for el in arr.values() do
      _env.out.print(el.string())
    end

whilst omitting the second generic type when instantiating - to leverage the default type, the compiler gives an error:

actor Main
  new create(env: Env) =>
    Foo[U8](env, 10)(3)
  

class Foo[T: Stringable val, Arr: Seq[T] ref = Array[T]]
  let _env: Env
  var arr: Arr = Arr
  
  new create(env: Env, v: T) =>
    _env = env
    arr.push(v)
    
  fun ref apply(v: T) =>
    arr.push(v)
    for el in arr.values() do
      _env.out.print(el.string())
    end

No problems to revert to Zulip, happy to do so if this is expected behavior. Thanks!

@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Sep 24, 2023
@jemc
Copy link
Member

jemc commented Sep 26, 2023

This is definitely something that I would have expected to work as desired.

The key issue here is that the compiler is comparing the constraint Seq[U8] to the default arg Array[T]. But to make this compile correctly it would either need to compare Seq[T] withArray[T] or alternatively, Seq[U8] with Array[U8].

We discussed this a bit in the sync call today, but haven't done any triaging yet into why this doesn't work as expected today. Needs further troubleshooting.

@jemc jemc reopened this Sep 26, 2023
@SeanTAllen SeanTAllen added help wanted Extra attention is needed needs investigation This needs to be looked into before its "ready for work" and removed discuss during sync Should be discussed during an upcoming sync labels Oct 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed needs investigation This needs to be looked into before its "ready for work"
Projects
None yet
Development

No branches or pull requests

4 participants