- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Implicits:I must be missing something really obvious
In the following, "Lit" is a case class. I have no idea why the
compiler is not accepting this definition, any help would be most
appreciated.
Error message
--------------------
/Users/Ken/NetBeansProjects/ScalaApplication1/src/scalaapplication1/
rex.scala:178: error: expected start of definition
implicit def stringToLit(s:String) = Lit(s)
^
---------------------
In a monospaced font, the "^" points to the "d" in def.










Re: Implicits:I must be missing something really obvious
Please give us more context?
Can we see the 10-15 lines each way?
My guess would be that you're defining an implicit at top level, and
it has to be within an object or class.
Re: Implicits:I must be missing something really obvious
Yes, you're right--it wasn't at top level. I only skimmed the chapter
on implicits, and they looked so simple :-)
Now I have to go figure out how to put it in an object or class and
make it available through the rest of the
same file. As I mentioned before about this library, I'm writing it as
a learning experience :-)
Thanks,
Ken
On Jan 27, 2009, at 2:27 PM, David Hall wrote:
> Please give us more context?
>
> Can we see the 10-15 lines each way?
>
> My guess would be that you're defining an implicit at top level, and
> it has to be within an object or class.
>
Re: Implicits:I must be missing something really obvious
object MyImplicits {
implicit def stringToLit(s:String) = Lit(s)
}
import MyImplicits._;
Re: Implicits:I must be missing something really obvious
Thanks! I'd tried several similar things, but hadn't hit on the magic
combo--I was doing import rex. ..., forgetting about import nesting.
Cheers,
Ken
On Jan 27, 2009, at 5:23 PM, David Hall wrote:
> object MyImplicits {
> implicit def stringToLit(s:String) = Lit(s)
> }
>
> import MyImplicits._;
>