Need for `implicit` keyword on parameters

102 views
Skip to first unread message

Craig Tataryn

unread,
Apr 26, 2016, 4:18:39 PM4/26/16
to scala-debate
Is there a real need for specifying the `implicit` keyword in front of a parameter?  Couldn't the compiler -- after parameter binding fails to satisfy all values -- then flip to a strategy which finds suitable implicit values for the missing parameters? 

Regards,

Craig

Dennis Haupt

unread,
Apr 26, 2016, 4:24:44 PM4/26/16
to Craig Tataryn, scala-debate
so you want to make implicits implicit? too much magic in my opinion

--
You received this message because you are subscribed to the Google Groups "scala-debate" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-debate...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Adriaan Moors

unread,
Apr 26, 2016, 4:28:48 PM4/26/16
to Craig Tataryn, scala-debate
Sure, technically we could do that, but I don't think it would be good language design -- documenting your intent is important. Type inference is great, but you should still provide full type signatures for public members. 

Without the implicit keyword error messages could not be as informative. Did you mean to have these arguments inferred? Did you want eta-expansion? Or should they have been provided explicitly?
The same argument could be made for the abstract keyword: the compiler could simply complain when you instantiate the class instead of when you accidentally define a class that can't be instantiated.

--

Craig Tataryn

unread,
Apr 26, 2016, 4:30:18 PM4/26/16
to Dennis Haupt, scala-debate
Well if you think about it, we're already doing so for functions. Bury this somewhere in your code:

implicit def toInt(s:String) = s.toInt

Then do this in scope:

val i:Int = "1"

Same level of magic IMHO

Craig

Naftoli Gugenheim

unread,
May 29, 2016, 9:49:00 PM5/29/16
to Craig Tataryn, Dennis Haupt, scala-debate

Are you proposing to also leave off the keyword in front of the thing that gets used implicitly? Or just when declaring the parameter that will accept it?

Craig Tataryn

unread,
May 30, 2016, 10:14:52 AM5/30/16
to Naftoli Gugenheim, Dennis Haupt, scala-debate
Just the keyword before parameter. The argument for this keyword placement seems to have to do with being explicit about when we want to make use of implicits. I'm not sure that is necessary though.

Craig


_____________________________
From: Naftoli Gugenheim <nafto...@gmail.com>
Sent: Sunday, May 29, 2016 8:48 PM
Subject: Re: [scala-debate] Need for `implicit` keyword on parameters
To: Dennis Haupt <d.ha...@gmail.com>, Craig Tataryn <cra...@tataryn.net>
Cc: scala-debate <scala-...@googlegroups.com>
Reply all
Reply to author
Forward
0 new messages