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

Offer type refinements on return types #67

Closed
propensive opened this issue Dec 23, 2021 · 2 comments
Closed

Offer type refinements on return types #67

propensive opened this issue Dec 23, 2021 · 2 comments
Assignees
Labels
api Relates to the API design enhancement An improvement to existing functionality minor Has only a small impact for the majority of users

Comments

@propensive
Copy link
Owner

propensive commented Dec 23, 2021

The return type of any Contextual value is fixed, but since the macro is transparent, it could be refined to a subtype. For example, in Guillotine the return type of a shell command such as sh"cat foo" could be typed as Command["cat"] instead of just Command. In this example, it would provide some further opportunities to have type inference automatically choose suitable return types for execution.

Known literal Text types from Gossamer could be refined to have the underlying String literal type available as a member.

This would probably be best provided through a mixin trait along the lines of:

trait Precision[State, Return]:
  interpolator: Interpolator[?, State, Return] =>
    type Refined[S <: String & Singleton] <: Return
    def result(state: State): String & Singleton

A user's implementation of result would provide the String based on the final State value which would be passed into the Refined type constructor to produce a new subtype of Return.

An alternative approach may be to change the Return type to Return[S <: String & Singleton] in all cases, and to provide a default implementation of result for users to override if they want this feature.

@propensive propensive self-assigned this Dec 23, 2021
@propensive propensive added api Relates to the API design enhancement An improvement to existing functionality minor Has only a small impact for the majority of users labels Jan 2, 2023
@propensive propensive added this to the Primevère milestone Jan 2, 2023
@propensive
Copy link
Owner Author

This may be achievable just by invoking the Contextual macro from another transparent inline macro, and applying the refinement.

@propensive
Copy link
Owner Author

This turns out to be completely possible without any special support from Contextual.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Relates to the API design enhancement An improvement to existing functionality minor Has only a small impact for the majority of users
Projects
Archived in project
Development

No branches or pull requests

1 participant