-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Syntax changes for new implicits #5825
Conversation
How about def cell(str: String) deriving (r: Row) = ... Then we can use the
derive ListOrd[A] for Ord[List[A]] deriving Ord[A] { ... }
println(maximum(xs) derive descending) // force derivation into a specific direction
println(maximum(xs) derive (descending derive IntOrd)) Expression Finally, val ord = derive[Ord[List[Int]]]
// or
val ord: Ord[List[Int]] = derive The possible use of "deriving" was also mentioned by @drdozer in the original thread. |
I believe |
d0e4615
to
b40b9d7
Compare
if I could humbly propose rule Monoid[Int] { ... }
rule Trivial: Monoid[Unit] { ... }
rule OptionMonoid[A]: given Monoid[A] => Monoid[Option[A]] { ... } It works quite well with the intution that we have "term inference" and we're defining rules for it. It's also, I think, easier to talk about "rules" than it is to talk about "implied instances". I'd say it's also easier to tell in all cases that this is a definition, as opposed to EDIT: Just to show this actually works quite well: a hypothetical error message when we have failed to infer a value could look as follows:
It's actually quite natural to talk about "rules" here. Also, previous propositions for |
33ca404
to
b5bd2b9
Compare
My last contribution to the bike-shedding -- I think we're honing in on something that's a local minima though.
My reasoning is that Being abile to use SAMs like this is a high priority for me. |
2a4a19e
to
06eb35f
Compare
Previously, `given ()` was legal, but it serves no purpose and only complicates things.
Parser.syntaxError contains a tweak that underlines the whole span of the current token, if it has a name. Tho make this work reliably we need to reset the name to null when reading a new token, since not every token sets a name.
It's `given A => B` instead of `A |=> B`.
# Conflicts: # tests/run-with-compiler-custom-args/tasty-interpreter/interpreter/TastyInterpreter.scala # tests/run-with-compiler-custom-args/tasty-interpreter/interpreter/TreeInterpreter.scala
Also: drop some doc pages that are no longer used.
Implied felt forced in this context
Token: INSTANCE -> IMPLIED Flag: Contextual -> Given
d7f1596
to
a1ffafc
Compare
Honest question, what is the benefit of using |
@bmeesters
These are the only changes relative to #5458. The rest is a documentation reorg where everything that has to do with context abstractions is now combined in one chapter. |
23a5f42
to
5f37755
Compare
These links are likely to change again, but we probably have some bikeshedding time before a consensus emerges from scala/scala3#5825
What I can't understand is: how (or whether) can I specify particular
def f1[F[_], T](xs: F[T]) given (o: Ord[T], f: Functor[F]) = ???
f1(whatever) given (o = IntOrd) // Can I pass the `given` parameter with a name?
def f2[F[_], T](xs: F[T]) given (Ord[T], Functor[F]) = ???
f2(whatever) given IntOrd // Can I pass only one?
def f3[F[_], G[_], T](xs: F[T], ys: G[T]) given (Ord[T], Functor[F]) given Functor[G] = ???
f3 given GIsFunctor // How can I pass parameter to the second `given` list skipping the first? |
That's not in the scope of this PR, but it could be a good idea to add this. |
@biboudis Can you give this a quick look? There's a lot of changes but it's all renamings or docs, so I think we should be able to merge this quickly. |
Is there a publicly visible build I can download with these changes in, or should I attempt to make one with git and sbt? I guess I'm asking if the checking process produces artifacts that we can use. |
|
||
An implied alias instance defines an implied instance that is equal to some expression. E.g., | ||
```scala | ||
implied ctx for ExecutionContext = currentThreadPool().context |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fail to see what is going on in this example. What is currentThreadPool()
? At what scope it resides? I think a fuller example is required here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just an example I think, like implied ctx for ExecutionContext = ???
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess @soronpo meant that it would be useful to use a very commonly known pattern to make the intention of the example clearer.
People might be mislead by trying to understand what the example is actually trying to achieve...
something more common might be
implied ctx for ExecutionContext = myActorSystem.dispatcher
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, but for me as a not frequenty Akka user currentThreadPool().context
is certainly more intuitively understandable than myActorSystem.dispatcher
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not if currentThreadPool
doesn't exist in any known library...
but my example was just out-of-the-blue, something more common ćould be found
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks very good
c2ddf4d
to
f397165
Compare
@Glavo Thanks for reporting. Can you please open an issue? |
Maybe someone could change the markdown links in the body of this PR (for posterity), they are all broken now. |
Hello. In section "Extension Methods", subsection "Implied Instances for Extension Methods" |
Hello again. In section "Implicit Conversions", subsection "Examples", the type parameter "T" in se end of the second exemple ("def complete[T]") look like not used... |
@flomebul Feel free to open a new PR to fix typos :) |
implied ... for
instead ofinstance of
given
instead ofwith
Direct link to docs, which together form a new part "Contextual Abstractions" in the reference.
Note: I have tried in these docs to do without the term
implicit
entirely (OK, there's stillimplied
). This was done in part as an experiment to see how far we can go. The other reason for doing it is that I have observed that we tend to useimplicit
quite indiscriminately and that the resulting terminology is not always precise and can be difficult to grasp for a newcomer. So I did this as an exercise in order to "wean myself off" the usage of the term. Once that's achieved we might decide that we want to bring back some usages ofimplicit
, so this is not necessarily a permanent ban. Update: I went back to"implicit conversion" - "inferable" felt too forced in that context.
Subsumes #5821. Follow-up to #5458.