implicit

GNU make implicit rules for batch file processing

本秂侑毒 提交于 2019-12-24 11:44:37
问题 I'd like to use GNU make to automate batch file processing, in my particular case I have a huge number of image files, I'd like to colorspace convert and reencode them to a custom file format. The file format encoder accepts only filenames on the command line, i.e. no stdio redirection. My file and directory structure is ./sourceimages/*.tif ./destimages/*.mie ./Makefile I wrote a peliminary Makefile with a pattern rule %.mie : %.tif tmpraw := $(shell mktemp --suffix=raw) convert $<

Implicit not found when omitting empty argument list

故事扮演 提交于 2019-12-24 02:55:15
问题 I have the following (simplified) code: case class Value[T](value: T) trait Absable[In,Out] { def absoluteValue(in: In): Out } implicit class AbsValue[In, Out](in: Value[In]) { def abs()(implicit ev: Absable[In, Out]): Value[Out] = Value(ev.absoluteValue(in.value)) } implicit def AbsNumeric[A : Numeric] = new Absable[A, A] { def absoluteValue(in: A) = implicitly[Numeric[A]].abs(in) } Now I want to use the abs function on a Value : scala> Value(-3).abs() res3: Value[Int] = Value(3) scala>

Wildcard Import, then Hide Particular Implicit?

限于喜欢 提交于 2019-12-23 17:18:03
问题 Given the following object with 2 implicits: scala> object Foo { | implicit def stringToInt(x: String) = 555 | implicit def stringToBoolean(x: String) = true | } warning: there were two feature warnings; re-run with -feature for details defined object Foo I can use them: scala> def f(x: Int) = x f: (x: Int)Int scala> import Foo._ import Foo._ scala> f("asdf") res0: Int = 555 scala> def g(b: Boolean) = b g: (b: Boolean)Boolean scala> g("asdfasdf") res1: Boolean = true Then, I tried to disable

Scala and Java - Implicit Parameters and Inheritance

人盡茶涼 提交于 2019-12-23 12:43:31
问题 The following code gives an error: package test trait Base { def method:String } trait Trait extends Base { def method()(implicit i:String):String = { "2" } } object Object extends Trait { } The error is "object creation impossible, since method method in class Base of type => String is not defined" The above error is fixed by following code package test trait Base { def method:String } trait Trait extends Base { def method:String = method()("String") // Over loading def method()(implicit i

Scala and Java - Implicit Parameters and Inheritance

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-23 12:40:18
问题 The following code gives an error: package test trait Base { def method:String } trait Trait extends Base { def method()(implicit i:String):String = { "2" } } object Object extends Trait { } The error is "object creation impossible, since method method in class Base of type => String is not defined" The above error is fixed by following code package test trait Base { def method:String } trait Trait extends Base { def method:String = method()("String") // Over loading def method()(implicit i

Implicit cast of class derived from template base class

不问归期 提交于 2019-12-23 10:57:07
问题 I've got a problem with implicit casting, templates and inheritance from template classes. The following is what I extracted from my project, I have left out that some classes are even abstract, but it does not have to do with the case. class A {}; class B : public A {}; template <typename T> class Base {}; class Derived : public Base<B> {}; int main() { Derived d; Base<A>* base = new Derived(); } Basically, I have a template base class Base that I derive Derived : public Base<B> from. Then I

How to implicitly wrap a value that can be null or an array into an Scala Option

元气小坏坏 提交于 2019-12-22 09:57:07
问题 I have this Java class in a Jar file included as a dependency of an Scala program (like the Axis jar): class MyClass { private String[] someStrings; public String[] getSomeStrings() { return someStrings; } } In my Scala program I have a Java API that return an instance of MyClass instance of MyClass to my program in Scala: val myInstance = JavaAPI.getInstanceOfMyClass() Then I try to use the someStrings array in my Scala program but it's null (let say that it wasn't properly initialized) for

Implicit parameters won't work on unapply. How to hide ubiquitous parameters from extractors?

橙三吉。 提交于 2019-12-22 08:50:29
问题 Apparently unapply/unapplySeq in extractor objects do not support implicit parameters. Assuming here an interesting parameter a, and a disturbingly ubiquitous parameter b that would be nice to hide away, when extracting c. [ EDIT ]: It appears something was broken in my intellij/scala-plugin installation that caused this. I cannot explain. I was having numerous strange problems with my intellij lately. After reinstalling, I can no longer reprodce my problem. Confirmed that unapply/unapplySeq

Unambiguous Subimplicits

天大地大妈咪最大 提交于 2019-12-22 07:42:35
问题 Consider the following code: class A { def print = println("A") } class B extends A { override def print = println("B") } def foo(implicit a: A) = a.print def bar(implicit a: A) = { implicit val b = new B foo } bar(new A) // B I am wondering why calling foo in bar isn't raising an ambiguous implicit values error. Of course implicit val b: A = new B will raise that error. Why does foo pick the implicit b and not the implicit a ? Or even more general: What are the rules what will be picked?

Why can't I implicit convert Scala's Function1 to java.util.function.Function?

隐身守侯 提交于 2019-12-21 18:05:37
问题 I'm trying to create a implicit conversion of Scala's Function1 to java.util.function.Function. Here's my code: object Java8ToScala extends App { implicit def javaFuncToScalaFunc[T, R](func1: Function[T, R]): function.Function[T,R] = { new function.Function[T, R] { override def apply(t: T): R = func1.apply(t) } } val javaFunc:function.Function[String,Int] = (s:String) => s.length println(javaFunc.apply("foo")) // this works private val strings = new util.ArrayList[String]() println(strings