implicit

Find root of implicit function in MATLAB

断了今生、忘了曾经 提交于 2019-12-06 12:45:56
I have an implicit function, for example: f(x,y) = x.^3 + x.*y + y.^2 - 36 I want to solve the root. So f(x,y) = 0 . Drawing the solution is easy: ezplot('x.^3 + x.*y + y.^2 - 36',[-10 10 -10 10]); However, I would like to have the data that is in the plot and not only the visual plot. So how do I find the data of the plot? i.e., how to get data OUT of a plot once it is made? If you supply an output argument to ezplot , it will give you a line handle . One of the properties of line handles is XData and YData . To extract data from the line handles, use get : LH = ezplot('x.^3 + x.*y + y.^2 -

scala: pimp my library with overloads

放肆的年华 提交于 2019-12-06 11:44:23
Any ideas why doesn't the following work? implicit def listExtensions[A](xs : List[A]) = new ListExtensions(xs) class ListExtensions[A](xs : List[A]) { def foreach[B](f: (A, Int) => B) { var i = 0; for (el <- xs) { f(el, i); i += 1; } } } var a = List(1, 2, 3); a foreach { (el, i) => println(el, i) }; When I compile this with fsc 2.8.1, I get the following error: "wrong number of parameters; expected = 1: a foreach { (el, i) => println(el, i) };". Am I doing something wrong or there simply ain't a way to add an overloaded method by the means of "pimp my library" trick? P.S. I wonder not about

Shapeless deconstruct tuple in type parameter declaration

眉间皱痕 提交于 2019-12-06 06:23:52
问题 I am using a RightFolder that returns a Tuple2 and would like to return the _1 part. The first version rightFoldUntupled1 works fine but uses an additional IsComposite typeclass. In the second version rightFoldUntupled2 I try to achieve the same without IsComposite by destructuring P as a Product2[_, Values] . That doesn't work any more - the compiler is happy to witness that P is a Product2[_,_] , but as soon as I use a named type parameter for _1 it doesn't compile any more. Any idea why?

Generate functions at macros expansion time

 ̄綄美尐妖づ 提交于 2019-12-06 05:13:29
问题 I would like to generate functions for a class accepting 1 type parameter case class C[T] (t: T) depending on the T type parameter. The functions I would like to generate are derived by the functions available on T . What I would like exactly, is to make all the functions available for T , also available for C . As an example for C[Int] , I would like to be able to call on C any function available on Int and dispatch the function call to the Int contained in C . val c1 = new C(1) assert(c1 +

Resolving Implicit for `Show` Typeclass Instance

不打扰是莪最后的温柔 提交于 2019-12-06 02:44:22
I'm trying to make Gender implement the Show typeclass. scala> trait Gender extends Show[Gender] defined trait Gender scala> case object Male extends Gender defined object Male scala> case object Female extends Gender defined object Female Next, I defined a function that calls show on an implicit Show[A] . scala> def f[A : Show](x: A): String = implicitly[Show[A]].shows(x) f: [A](x: A)(implicit evidence$1: scalaz.Show[A])String Finally, I created an implicit class for Show[Gender] : scala> implicit class GenderShows(g: Gender) extends Show[Gender] { | g match { | case Male => "Male" | case

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

萝らか妹 提交于 2019-12-06 01:55:11
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(str <- myInstance.getSomeStrings()) ... So this throws a NullPointerException . I've found that in

Does implementing Interface both implicit and explicit make sense?

怎甘沉沦 提交于 2019-12-05 23:05:12
问题 I'm currently studying for my MS 70-515 exam. In one of the practices the author implements an interface both implicit as well as explicit. The explicit implementation just calls the implicit implementation. The explicit implementation is just listed without an explanation. Does it make sense to have both an implicit and an explicit implementation of the interface? I would think the explicit implementation is redundant (in this case). public class PassTextBox : TextBox, IScriptControl {

Scala Generics and Numeric Implicits

拈花ヽ惹草 提交于 2019-12-05 21:13:21
问题 I need to pass two functions as parameters to a scala function. That function should then evaluate them and get a number from them where it will then operate on. This number can be either a Int, Double or any other numeric type. I would like the function to work, whatever the types it is working with. The example bellow explains the issue. import Numeric.Implicits._ class Arithmetic[T : Numeric](val A: Connector[T], val B: Connector[T]) { val sum = new Connector({ A.value + B.value }) } class

Scala and cats: Implicit conversion to identity monad

房东的猫 提交于 2019-12-05 19:04:50
I have a function that computes sum of squares for numeric types as shown below. import cats.syntax.functor._ import cats.syntax.applicative._ import cats.{Id, Monad} import scala.language.higherKinds object PowerOfMonads { /** * Ultimate sum of squares method * * @param x First value in context * @param y Second value in context * @tparam F Monadic context * @tparam T Type parameter in the Monad * @return Sum of squares of first and second values in the Monadic context */ def sumOfSquares[F[_]: Monad, A, T >: A](x: F[A], y: F[A])(implicit num: Numeric[T]) : F[T] = { def square(value:T): T =

create an ambiguous low priority implicit

坚强是说给别人听的谎言 提交于 2019-12-05 16:47:07
问题 Consider the default codec as offered in the io package. implicitly[io.Codec].name //res0: String = UTF-8 It's a "low priority" implicit so it's easy to override without ambiguity. implicit val betterCodec: io.Codec = io.Codec("US-ASCII") implicitly[io.Codec].name //res1: String = US-ASCII It's also easy to raise its priority level. import io.Codec.fallbackSystemCodec implicit val betterCodec: io.Codec = io.Codec("US-ASCII") implicitly[io.Codec].name //won't compile: ambiguous implicit values