|
Implicit parameters: msg#00004lang.scala
Consider: def log(msg: String)(implicit title: String) = Console.println("Log: " + title + '|' + msg); def log(msg: String): unit = log(msg)("Default"); implicit val title = "Title"; log("Some message"); log("Another message")("Direct Title"); Scala doesn't currently have default values for parameters, but we can create multiple versions of a function that call a basic version, as above. The compiler I have now chooses the implicit version of the function always. I wonder about the following syntax for Param: implicit varname: Type [=#symbolFilter][=constvalue] def log(msg: String)(implicit title: String =#logTitle ="No Title") I can then write: def func = { def inner = { implicit val logTitle = "inner"; log("A message"); } log("Hello"); } I don't think the symbol lookup has any effect on type safety. The implicit parameter as currently specified is already doing a search of the context for a symbol of the right type; =# directs the search to match only symbols tagged with implicit that match the filter. If the defaultValue is present that value is used if the implicit search fails. I like the unification of default parameters and views that the current implicit approach represents, but wonder if the symbol selection filter provides additional and necessary precision, particularly when type does not provide enough of a discriminator. RJ |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | New linearization: 00004, Judson, Ross |
|---|---|
| Next by Date: | RE: Scala Eclipse Plugin Beta: 00004, Judson, Ross |
| Previous by Thread: | New linearizationi: 00004, Judson, Ross |
| Next by Thread: | RE: Scala Eclipse Plugin Beta: 00004, Judson, Ross |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |