Skip to content

give _ToProc#to_proc a return type#1223

Merged
soutaro merged 1 commit intoruby:masterfrom
ParadoxV5:_ToProc
Feb 6, 2023
Merged

give _ToProc#to_proc a return type#1223
soutaro merged 1 commit intoruby:masterfrom
ParadoxV5:_ToProc

Conversation

@ParadoxV5
Copy link
Copy Markdown
Contributor

I don’t know what purpose are the interfaces in builtin.rbs, but I do use them for implicit conversion. The return of _ToProc#to_proc, however, is untyped and I cannot see why. This is the contract for implicit conversion to a block when prefixed with & (an_array.map(&a_to_proc)).

@ParadoxV5
Copy link
Copy Markdown
Contributor Author

ParadoxV5 commented Feb 4, 2023

[Discussion] just typing it as Proc isn’t very useful since RBS has “Proc type”s.

  • We could make it _ToProc[^(specific_arg_types) -> specific_return type] so one can specify the resulting Proc’s contract.
  • The current solution is to write a custom interface that defines the desired contract: def to_proc: ^(specific_arg_types) -> specific_return type.

Regardless of which bullet point to adopt, _ToProc#to_proc doesn’t make sense not having a return type – unless _ToProc shouldn’t exist fundamentally.

@soutaro
Copy link
Copy Markdown
Member

soutaro commented Feb 6, 2023

Thanks @ParadoxV5,

Having Proc is an improvement while it doesn't make much sense, as you said. It makes sense that passing a proc type to the type parameter, but still it's not very useful because we don't have something to express the constraints on the arguments of a proc/method.

@soutaro soutaro added this to the RBS 3.0 milestone Feb 6, 2023
@soutaro soutaro merged commit d631c0a into ruby:master Feb 6, 2023
@ParadoxV5 ParadoxV5 mentioned this pull request Nov 20, 2023
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

Successfully merging this pull request may close these issues.

2 participants