Inconsistent type inference for context functions and inferable type aliases #12782
Kordyjan
started this conversation in
General Discussion
Replies: 1 comment
-
I recently came across a similar issue and I agree it would be really helpful if there was a limited way to make context function types inferable to make code cleaner/less verbose. The idea is that you may want to bind some value to a variable and use it as a context function (like in the examples in the first post). I would imagine something like: For every val/def binding without explicit type ascription, if all “leafs” of the right-hand-side AST agree on the So, Would there be any interest in such a feature? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In pretty much every situation context functions behave the same as any other type. For example
is a proper, working piece of code. Inference of context function type works as expected.
On the other hand, if the compiler knows ahead that inferred type is going to be the context function, the inference stops working.
fails during type-checking. If we explicitly specify the type of
b
asCtx ?=> Double
it is working.I assume this is not a bug but a design decision to avoid context bounds propagating upwards. This restriction can be confusing if context-bound is expressed as a type alias, such as in case:
that will fail with a confusing error, even though it is something that seems to be reasonable in some DSLs. Also, frequent repetition of types that may be easily inferable can make DSL less readable.
Is it possible to add annotation applicable to type aliases that can make them inferable, even if they are context functions?
Something like:
would be perfect for my intended use cases.
Beta Was this translation helpful? Give feedback.
All reactions