Quantcast

Implicit Not Visible in Scope

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Implicit Not Visible in Scope

Joe San
In the following example., I was expecting something to be printed at line 1 and 2, but strangely I do not see that happening. My IDE complaints on line 3 that it is an unused import statement. Any ideas what is going wrong?

import scala.io.Source


class CSVReader[A] {
def parse(path: String) = ReaderWithFile[A](path)

case class ReaderWithFile[A](path: String) {
def using(cfg: CSVParserConfig): Seq[A] = {
val lines = Source.fromFile(path).getLines().mkString("\n")
println(lines) // line 1
println(cfg) // line 2
null
}
}
object ReaderWithFile {
implicit def parser2parsed[A](parser: ReaderWithFile[A]): Seq[A] = parser.using(defaultParserCfg)
}
}
object CSVReader extends App {

def parser[A] = new CSVReader[A]

val myParser = parser

import myParser.ReaderWithFile.parser2parsed // line 3, IDE says that this import is unused!

myParser parse "csv-parser/test.csv" // expecting line 1 and 2 getting printed, but not!

// but this works
myParser parse "csv-parser/test.csv" using CSVParserConfig()

}

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Implicit Not Visible in Scope

Oliver Ruebenacker

     Hello,

  Not sure why you expect lines 1 and 2 to be printed is method using is not called?

  Also, parser2parsed is not used.

     Best, Oliver

On Fri, Apr 21, 2017 at 2:11 PM, Joe San <[hidden email]> wrote:
In the following example., I was expecting something to be printed at line 1 and 2, but strangely I do not see that happening. My IDE complaints on line 3 that it is an unused import statement. Any ideas what is going wrong?

import scala.io.Source


class CSVReader[A] {
def parse(path: String) = ReaderWithFile[A](path)

case class ReaderWithFile[A](path: String) {
def using(cfg: CSVParserConfig): Seq[A] = {
val lines = Source.fromFile(path).getLines().mkString("\n")
println(lines) // line 1
println(cfg) // line 2
null
}
}
object ReaderWithFile {
implicit def parser2parsed[A](parser: ReaderWithFile[A]): Seq[A] = parser.using(defaultParserCfg)
}
}
object CSVReader extends App {

def parser[A] = new CSVReader[A]

val myParser = parser

import myParser.ReaderWithFile.parser2parsed // line 3, IDE says that this import is unused!

myParser parse "csv-parser/test.csv" // expecting line 1 and 2 getting printed, but not!

// but this works
myParser parse "csv-parser/test.csv" using CSVParserConfig()

}

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



--
Oliver Ruebenacker
Senior Software Engineer, Diabetes Portal, Broad Institute

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Implicit Not Visible in Scope

Joe San
So the idea is if the user calls just this:

 myParser parse "csv-parser/test.csv"

I want the default to be applied!

On Fri, Apr 21, 2017 at 9:10 PM, Oliver Ruebenacker <[hidden email]> wrote:

     Hello,

  Not sure why you expect lines 1 and 2 to be printed is method using is not called?

  Also, parser2parsed is not used.

     Best, Oliver

On Fri, Apr 21, 2017 at 2:11 PM, Joe San <[hidden email]> wrote:
In the following example., I was expecting something to be printed at line 1 and 2, but strangely I do not see that happening. My IDE complaints on line 3 that it is an unused import statement. Any ideas what is going wrong?

import scala.io.Source


class CSVReader[A] {
def parse(path: String) = ReaderWithFile[A](path)

case class ReaderWithFile[A](path: String) {
def using(cfg: CSVParserConfig): Seq[A] = {
val lines = Source.fromFile(path).getLines().mkString("\n")
println(lines) // line 1
println(cfg) // line 2
null
}
}
object ReaderWithFile {
implicit def parser2parsed[A](parser: ReaderWithFile[A]): Seq[A] = parser.using(defaultParserCfg)
}
}
object CSVReader extends App {

def parser[A] = new CSVReader[A]

val myParser = parser

import myParser.ReaderWithFile.parser2parsed // line 3, IDE says that this import is unused!

myParser parse "csv-parser/test.csv" // expecting line 1 and 2 getting printed, but not!

// but this works
myParser parse "csv-parser/test.csv" using CSVParserConfig()

}

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



--
Oliver Ruebenacker
Senior Software Engineer, Diabetes Portal, Broad Institute

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

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Implicit Not Visible in Scope

Oliver Ruebenacker
  Not sure what you mean by "default"?

  Since myParser is of type CSVReader, it has a parse method that takes a String, so there is no reason for the compiler to look for an implicit conversion.

On Fri, Apr 21, 2017 at 3:23 PM, Joe San <[hidden email]> wrote:
So the idea is if the user calls just this:

 myParser parse "csv-parser/test.csv"

I want the default to be applied!

On Fri, Apr 21, 2017 at 9:10 PM, Oliver Ruebenacker <[hidden email]> wrote:

     Hello,

  Not sure why you expect lines 1 and 2 to be printed is method using is not called?

  Also, parser2parsed is not used.

     Best, Oliver

On Fri, Apr 21, 2017 at 2:11 PM, Joe San <[hidden email]> wrote:
In the following example., I was expecting something to be printed at line 1 and 2, but strangely I do not see that happening. My IDE complaints on line 3 that it is an unused import statement. Any ideas what is going wrong?

import scala.io.Source


class CSVReader[A] {
def parse(path: String) = ReaderWithFile[A](path)

case class ReaderWithFile[A](path: String) {
def using(cfg: CSVParserConfig): Seq[A] = {
val lines = Source.fromFile(path).getLines().mkString("\n")
println(lines) // line 1
println(cfg) // line 2
null
}
}
object ReaderWithFile {
implicit def parser2parsed[A](parser: ReaderWithFile[A]): Seq[A] = parser.using(defaultParserCfg)
}
}
object CSVReader extends App {

def parser[A] = new CSVReader[A]

val myParser = parser

import myParser.ReaderWithFile.parser2parsed // line 3, IDE says that this import is unused!

myParser parse "csv-parser/test.csv" // expecting line 1 and 2 getting printed, but not!

// but this works
myParser parse "csv-parser/test.csv" using CSVParserConfig()

}

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



--
Oliver Ruebenacker
Senior Software Engineer, Diabetes Portal, Broad Institute

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

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



--
Oliver Ruebenacker
Senior Software Engineer, Diabetes Portal, Broad Institute

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Implicit Not Visible in Scope

Joe San
So what I want to achieve is effectively the following:

myParser parse "/Users/jothi/Projects/Private/scala-projects/csv-parser/test.csv"

// but this works
myParser parse "/Users/jothi/Projects/Private/scala-projects/csv-parser/test.csv" using CSVParserConfig(Pipe)
So if the using CSVParserConfig is not provided, I should be able to box using defaultCSVParserConfig into the call!

But if the caller does not provide a specific config, I should apply the default as specified in the implicit

implicit def parser2parsed[B](parser: ReaderWithFile[B]): Seq[B] = parser.using(defaultParserCfg)

On Fri, Apr 21, 2017 at 9:28 PM, Oliver Ruebenacker <[hidden email]> wrote:
  Not sure what you mean by "default"?

  Since myParser is of type CSVReader, it has a parse method that takes a String, so there is no reason for the compiler to look for an implicit conversion.

On Fri, Apr 21, 2017 at 3:23 PM, Joe San <[hidden email]> wrote:
So the idea is if the user calls just this:

 myParser parse "csv-parser/test.csv"

I want the default to be applied!

On Fri, Apr 21, 2017 at 9:10 PM, Oliver Ruebenacker <[hidden email]> wrote:

     Hello,

  Not sure why you expect lines 1 and 2 to be printed is method using is not called?

  Also, parser2parsed is not used.

     Best, Oliver

On Fri, Apr 21, 2017 at 2:11 PM, Joe San <[hidden email]> wrote:
In the following example., I was expecting something to be printed at line 1 and 2, but strangely I do not see that happening. My IDE complaints on line 3 that it is an unused import statement. Any ideas what is going wrong?

import scala.io.Source


class CSVReader[A] {
def parse(path: String) = ReaderWithFile[A](path)

case class ReaderWithFile[A](path: String) {
def using(cfg: CSVParserConfig): Seq[A] = {
val lines = Source.fromFile(path).getLines().mkString("\n")
println(lines) // line 1
println(cfg) // line 2
null
}
}
object ReaderWithFile {
implicit def parser2parsed[A](parser: ReaderWithFile[A]): Seq[A] = parser.using(defaultParserCfg)
}
}
object CSVReader extends App {

def parser[A] = new CSVReader[A]

val myParser = parser

import myParser.ReaderWithFile.parser2parsed // line 3, IDE says that this import is unused!

myParser parse "csv-parser/test.csv" // expecting line 1 and 2 getting printed, but not!

// but this works
myParser parse "csv-parser/test.csv" using CSVParserConfig()

}

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



--
Oliver Ruebenacker
Senior Software Engineer, Diabetes Portal, Broad Institute

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

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



--
Oliver Ruebenacker
Senior Software Engineer, Diabetes Portal, Broad Institute


--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Implicit Not Visible in Scope

Oliver Ruebenacker
  If the expression would appear in a context where Seq[A] is required, then the implicit conversion would apply (for example, if you add a ": Seq[A]" at the end. BTW, what is A? It's nowhere defined.

  Otherwise, why not just add an argument with default value to the parse method?

On Fri, Apr 21, 2017 at 3:34 PM, Joe San <[hidden email]> wrote:
So what I want to achieve is effectively the following:

myParser parse "/Users/jothi/Projects/Private/scala-projects/csv-parser/test.csv"

// but this works
myParser parse "/Users/jothi/Projects/Private/scala-projects/csv-parser/test.csv" using CSVParserConfig(Pipe)
So if the using CSVParserConfig is not provided, I should be able to box using defaultCSVParserConfig into the call!

But if the caller does not provide a specific config, I should apply the default as specified in the implicit

implicit def parser2parsed[B](parser: ReaderWithFile[B]): Seq[B] = parser.using(defaultParserCfg)

On Fri, Apr 21, 2017 at 9:28 PM, Oliver Ruebenacker <[hidden email]> wrote:
  Not sure what you mean by "default"?

  Since myParser is of type CSVReader, it has a parse method that takes a String, so there is no reason for the compiler to look for an implicit conversion.

On Fri, Apr 21, 2017 at 3:23 PM, Joe San <[hidden email]> wrote:
So the idea is if the user calls just this:

 myParser parse "csv-parser/test.csv"

I want the default to be applied!

On Fri, Apr 21, 2017 at 9:10 PM, Oliver Ruebenacker <[hidden email]> wrote:

     Hello,

  Not sure why you expect lines 1 and 2 to be printed is method using is not called?

  Also, parser2parsed is not used.

     Best, Oliver

On Fri, Apr 21, 2017 at 2:11 PM, Joe San <[hidden email]> wrote:
In the following example., I was expecting something to be printed at line 1 and 2, but strangely I do not see that happening. My IDE complaints on line 3 that it is an unused import statement. Any ideas what is going wrong?

import scala.io.Source


class CSVReader[A] {
def parse(path: String) = ReaderWithFile[A](path)

case class ReaderWithFile[A](path: String) {
def using(cfg: CSVParserConfig): Seq[A] = {
val lines = Source.fromFile(path).getLines().mkString("\n")
println(lines) // line 1
println(cfg) // line 2
null
}
}
object ReaderWithFile {
implicit def parser2parsed[A](parser: ReaderWithFile[A]): Seq[A] = parser.using(defaultParserCfg)
}
}
object CSVReader extends App {

def parser[A] = new CSVReader[A]

val myParser = parser

import myParser.ReaderWithFile.parser2parsed // line 3, IDE says that this import is unused!

myParser parse "csv-parser/test.csv" // expecting line 1 and 2 getting printed, but not!

// but this works
myParser parse "csv-parser/test.csv" using CSVParserConfig()

}

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



--
Oliver Ruebenacker
Senior Software Engineer, Diabetes Portal, Broad Institute

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

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



--
Oliver Ruebenacker
Senior Software Engineer, Diabetes Portal, Broad Institute





--
Oliver Ruebenacker
Senior Software Engineer, Diabetes Portal, Broad Institute

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Implicit Not Visible in Scope

Joe San
Adding a default argument would not let me write the call as expressive as it is now!

On Fri, Apr 21, 2017 at 9:44 PM, Oliver Ruebenacker <[hidden email]> wrote:
  If the expression would appear in a context where Seq[A] is required, then the implicit conversion would apply (for example, if you add a ": Seq[A]" at the end. BTW, what is A? It's nowhere defined.

  Otherwise, why not just add an argument with default value to the parse method?

On Fri, Apr 21, 2017 at 3:34 PM, Joe San <[hidden email]> wrote:
So what I want to achieve is effectively the following:

myParser parse "/Users/jothi/Projects/Private/scala-projects/csv-parser/test.csv"

// but this works
myParser parse "/Users/jothi/Projects/Private/scala-projects/csv-parser/test.csv" using CSVParserConfig(Pipe)
So if the using CSVParserConfig is not provided, I should be able to box using defaultCSVParserConfig into the call!

But if the caller does not provide a specific config, I should apply the default as specified in the implicit

implicit def parser2parsed[B](parser: ReaderWithFile[B]): Seq[B] = parser.using(defaultParserCfg)

On Fri, Apr 21, 2017 at 9:28 PM, Oliver Ruebenacker <[hidden email]> wrote:
  Not sure what you mean by "default"?

  Since myParser is of type CSVReader, it has a parse method that takes a String, so there is no reason for the compiler to look for an implicit conversion.

On Fri, Apr 21, 2017 at 3:23 PM, Joe San <[hidden email]> wrote:
So the idea is if the user calls just this:

 myParser parse "csv-parser/test.csv"

I want the default to be applied!

On Fri, Apr 21, 2017 at 9:10 PM, Oliver Ruebenacker <[hidden email]> wrote:

     Hello,

  Not sure why you expect lines 1 and 2 to be printed is method using is not called?

  Also, parser2parsed is not used.

     Best, Oliver

On Fri, Apr 21, 2017 at 2:11 PM, Joe San <[hidden email]> wrote:
In the following example., I was expecting something to be printed at line 1 and 2, but strangely I do not see that happening. My IDE complaints on line 3 that it is an unused import statement. Any ideas what is going wrong?

import scala.io.Source


class CSVReader[A] {
def parse(path: String) = ReaderWithFile[A](path)

case class ReaderWithFile[A](path: String) {
def using(cfg: CSVParserConfig): Seq[A] = {
val lines = Source.fromFile(path).getLines().mkString("\n")
println(lines) // line 1
println(cfg) // line 2
null
}
}
object ReaderWithFile {
implicit def parser2parsed[A](parser: ReaderWithFile[A]): Seq[A] = parser.using(defaultParserCfg)
}
}
object CSVReader extends App {

def parser[A] = new CSVReader[A]

val myParser = parser

import myParser.ReaderWithFile.parser2parsed // line 3, IDE says that this import is unused!

myParser parse "csv-parser/test.csv" // expecting line 1 and 2 getting printed, but not!

// but this works
myParser parse "csv-parser/test.csv" using CSVParserConfig()

}

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



--
Oliver Ruebenacker
Senior Software Engineer, Diabetes Portal, Broad Institute

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

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



--
Oliver Ruebenacker
Senior Software Engineer, Diabetes Portal, Broad Institute





--
Oliver Ruebenacker
Senior Software Engineer, Diabetes Portal, Broad Institute


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