{"id":4467,"date":"2014-03-30T11:21:04","date_gmt":"2014-03-30T11:21:04","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/problem-about-implicit-collection-of-common-programming-errors\/"},"modified":"2014-03-30T11:21:04","modified_gmt":"2014-03-30T11:21:04","slug":"problem-about-implicit-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/problem-about-implicit-collection-of-common-programming-errors\/","title":{"rendered":"problem about implicit-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/6d6bc94324b83d8e4c11dcd01d618933?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nRafael<br \/>\nc# matrix operator-keyword implicit<br \/>\nI have this class:public class SmartTable : DataTable {public string this[int Row, int Column] { &#8230; }public string this[int Row, string Column] { &#8230; } }and i want to add an implicit operator on THIS[,]then i could use:string s = smartT[a,b];orint i = smartT[a,b];I googled this but even I don&#8217;t know how to search it.I tried (based on IntelliSense) declare something like:public static implicit operator int[int r, int c](&#8230;) {&#8230;}orpublic static implicit operator int (SmartTable sm, int a, int<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/39cc1edbbcd69eca088fe2447d8d095b?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nJacek Kolodziejczyk<br \/>\nscala implicit<br \/>\nCould you please explain why the second call to listen method does not work and suggest a solution to make it work?object Example extends App {case class Event(kind: Int)trait Listener { def handle(e: Event) }val listeners = scala.collection.mutable.Map[Int, Listener]()def emit(e: Event) = listeners.get(e.kind).foreach(_.handle(e))def listen(kind: Int)(f: (Event) =&gt; Unit) {val l = new Listener() { override def handle(e: Event) = f(e) }listeners += kind -&gt; l}implicit def unit2EventUnit(f: =<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/c6c6ea18f5cbad028f28bcfe7ce531e1?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nMika\u00ebl Mayer<br \/>\nscala apply implicit<br \/>\nI tried the following to create an option-checking style in code:object Test {trait Checkobject x extends Checkdef option() = falsedef option(xx: Check) = trueimplicit class AugmentCheck(s: String) {def apply() = &#8220;&#8221;def apply(xx: Check) = s} } import Test._val delete = option ( x ) val force = option ( )val res = &#8220;mystring&#8221; ( )But I face the following problem:&lt;console&gt;:11: error: type mismatch;found : String(&#8220;mystring&#8221;)required: ?{def apply: ?} Note that implicit conversions are not<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/e44e4e7559a4babc6013dfd4f3c2a5dd?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nfuzzy<br \/>\nc# .net interface implicit explicit<br \/>\nWhat are the differences in implementing interfaces implicitly and explicitly in C#?When should you use implicit and when should you use explicit?Are there any pros and\/or cons to one or the other?<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/4fb277fc5fa9faaba142da9b31563dcc?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\npsubsee2003<br \/>\nc# c#-4.0 operator-keyword implicit explicit<br \/>\nI have never done any extensive work with overloading operators, especially the implicit and explicit conversions.However, I have several numeric parameters that are used frequently, so I am creating a struct as a wrapper around a numeric type to strongly type these parameters. Here&#8217;s an example implementation:public struct Parameter {private Byte _value;public Byte Value { get { return _value; } }public Parameter(Byte value){_value = value;}\/\/ other methods (GetHashCode, Equals, ToString, etc)<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/e5d70b07efe98c43d8bdb01c0431f825?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nBill<br \/>\nscala implicit<br \/>\nI had a strange bug yesterday that I eventually reduced to the following code:Welcome to Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_29). Type in expressions to have them evaluated. Type :help for more information.scala&gt; class X extends Function[String, Int] { def apply(x: String) = Integer.parseInt(x) } defined class Xscala&gt; implicit val x = new X x: X = &lt;function1&gt;scala&gt; &#8220;56&#8221; \/ 2 res2: Int = 28I expect this to throw an exception, since String doesn&#8217;t<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/b043ead577679feb2f4f4c3e4bb4700f?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nRafal Rawicki<br \/>\nscala implicit<br \/>\nConsider following code in Scala:object Test {class A {}class B extends A {}class AI extends A {def sayHello: String = &#8220;Hello from AI&#8221;}implicit def AtoAI(a: A): AI = aclass BI extends B {def sayHello: String = &#8220;Hello from BI&#8221;}implicit def BtoBI(b: B): BI = bdef main(args: Array[String]) {val a = new Aprintln(a.sayHello)val b = new Bprintln(b.sayHello)} }The use of implicits results in looping code. In fact, disassemblying reveals, that generated conversion methods have only a goto 0 inside:publi<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/caf32b96d00d6a3ff892fa67feff07fe?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nJean-Philippe Pellet<br \/>\nscala implicit<br \/>\nSuppose I want to wrap code that can throw exceptions with a try-catch block that logs the exception and continues. Something like:loggingExceptions {\/\/ something dangerous }Ideally, I would like to use for logging the Logger defined on the calling object, if any (and if none, get a compile-time error). I&#8217;d love to define something like this:def loggingExceptions[L &lt;: { def logger: Logger }](work: =&gt; Unit)(implicit objectWithLogger: L): Unit = {try {work} catch {case t: Exception =&gt; obj<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/PGxlu.jpg?s=32&amp;g=1\" \/><br \/>\nRAbraham<br \/>\nscala design implicit-conversion implicit<br \/>\nI have a question on type design. Why does Int not extend the Ordered trait. Isn&#8217;t Int ordered by nature?Instead, the scala library provides implicit &#8216;orderer&#8217; methods which convert Int to Ordered[Int]. What are the design choices being made here?Example taken from the book Programming in Scaladef maxListImpParm[T &lt;% Ordered[T]](elements:List[T]):T= &#8230;maxListImpParm(List(1,5,10,3)) \/\/ works because of implicit methods<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/472e704d0ce3cf7339a45df034e9e4a5?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nFireSBurnsmuP<br \/>\nc# casting asp.net-4.0 implicit<br \/>\nAlright, I&#8217;ve been trying to find any information on this for a while. I built a small class to see how hard type-safe-enums are to implement for strings, because I want to use them for database field-names and such. I&#8217;ve never liked the fact that enums could only be used for integers. However, even though I have implemented an implicit operator for this class, every time I try to use it, it gives me an invalid cast exception. I&#8217;m at a loss, as I can see nothing wrong with my code at this point.<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/bb95167937ee39b89251fcac6377951a?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\narootbeer<br \/>\nc# casting implicit<br \/>\nPreserved question &#8211; see Edit at the bottom I&#8217;m working on a small functional library, basically to provide some readability by hiding basic cyclomatic complexities. The provider is called Select&lt;T&gt; (with a helper factory called Select), and usage is similar topublic Guid? GetPropertyId(&#8230;) {return Select.Either(TryToGetTheId(&#8230;)).Or(TrySomethingElseToGetTheId(&#8230;)).Or(IGuessWeCanTryThisTooIfWeReallyHaveTo(&#8230;))\/\/etc.; }and the library will take care of the short circuiting, etc. I als<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/8c82898ff7f2247a7fc0c1e224b4b3de?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nW.P. McNeill<br \/>\nscala builder implicit<br \/>\nI am writing a Scala class that implements a 2-dimensional matrix of arbitrary objects. I need the class to be more specialized than nested pair of IndexedSeq objects, but extending a collections class is overkill, so I&#8217;m writing my own. In order to return the correct type from methods in my matrix class, I am using the implicit builder idiom, but at runtime I get a &#8220;could not find implicit value for parameter&#8221; error which I don&#8217;t understand.A stripped-down version of my matrix class looks like<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/7993bfc44f2372777651b3da035c0c77?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nJustin<br \/>\nc# operator-keyword implicit implicit-cast<br \/>\nI have a class similar to the following that uses an internal List:public class MyList&lt;T&gt; : IEnumerable&lt;T&gt; {private List&lt;T&gt; _lstInternal;public MyList(){_lstInternal = new List&lt;T&gt;();}public static implicit operator List&lt;T&gt;(MyList&lt;T&gt; toCast){return toCast._lstInternal;}}When I try to pass MyList&lt;object&gt; to a function that takes a List&lt;object&gt;, I get an InvalidCastException. Why?<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/56d3ad2d6f054a03a54b68dc8152866f?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nHesam<br \/>\nandroid android-intent qr-code implicit<br \/>\nIn my application I need to read Qr code. I searched the net and found Zing codes however lots of developers had problem with using it and it seems it is buggy!If i assume that my customers has qr reader installed on their device, how can i use those applications and call them via implicit intents? if user doesn&#8217;t have any qr reader, what will happen to the application? if it crashes, may i ask user to download for example QrDroid and after that use it?<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/68aff80585079688f0c006a85a6a4b02?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nSiverchen<br \/>\niphone ios implicit reinstall<br \/>\nthe previous version of the app has some implicit with the newest version, and if users install the new version, maybe the app will be crashed, so is there any way to remove the previous version when I install the new version, thanks~~<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/03347db2fae30fa50f1571d280b1eca3?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nConstantin<br \/>\nc include printf implicit declarations<br \/>\nSession transcript:&gt;type lookma.c int main() {printf(&#8220;%s&#8221;, &#8220;no stdio.h&#8221;); }&gt;cl lookma.c Microsoft (R) 32-bit C\/C++ Optimizing Compiler Version 14.00.50727.762 for 80&#215;86 Copyright (C) Microsoft Corporation. All rights reserved.lookma.c Microsoft (R) Incremental Linker Version 8.00.50727.762 Copyright (C) Microsoft Corporation. All rights reserved.\/out:lookma.exe lookma.obj&gt;lookma no stdio.h<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/79d4ad786de42b48cf88ba7e9dfae8c4?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nEricson Willians<br \/>\nc declaration implicit<br \/>\nI had a function in a file &#8220;draw.h&#8221;:void TileSystem() {\/\/ Some code here. }And in the &#8220;main.c&#8221; file, I call it, because I have #included &#8220;draw.h&#8221; in the file. The function works nicely well!!But then, I decide to rename the function tovoid CreateTileSystem() {\/\/ Some code here. }And I get the following output:gcc main.c -std=c99 -o main `pkg-config &#8211;cflags &#8211;libs allegro-5.0 allegro_acodec-5.0 allegro_audio-5.0 allegro_color-5.0 allegro_dialog-5.0 allegro_font-5.0 allegro_image-<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/730f1a63ba0e2f2ba6c8e7587fafde88?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nDemonicImpact<br \/>\nc unix declaration implicit<br \/>\nIn the following code, I get a warning that there is an implicit declaration of function getpgid. I know its only a warning, but its for a class and the professor wants us to treat warnings as errors. So, help please. I have included the appropriate header file as well so I have no idea whats wrong:#include &lt;unistd.h&gt;pid_t pid, pgid;if ((pgid = getpgid(pid)) &lt; 0) {app_error(&#8220;Failure to get process group ID&#8221;); }<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/4de94e14f977802057b0109d079d95a1?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nIskar Jarak<br \/>\nc typedef c99 implicit c89<br \/>\nWith curiosity of the definition and scope of typedef I have written below C code in 2 .c files:main.c#include &lt;stdio.h&gt;int main() {int a = 5, b = 6;printf(&#8220;a = %d, b = %d\\n&#8221;, a, b);swap(&amp;a, &amp;b);printf(&#8220;a = %d, b = %d\\n&#8221;, a, b); }swap.ctypedef T;void swap(T* a, T* b) {T t = *a;*a = *b;*b = t; }To my surprise, the code files could be compiled with Visual Studio C compiler (cl.exe \/Tc main.c swap.c)And the program runs correctly! From my understanding, typedef requires 2 parameters,<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/fab3a99e4e2557b8878261d39822776c?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nAaron Patzer<br \/>\nscala collections implicit<br \/>\nI can&#8217;t seem to create a SortedSet that also mixes in SynchronizedSet. The crux of the problem is SortedSet requires an implicit Ordering object.val orderByIdThenName = Ordering[(Int, String)].on[Foo](foo =&gt; foo.id -&gt; foo.name) new mutable.TreeSet[Foo]()(orderByIdThenName) \/\/ &lt;- Works fine and is Ordered new mutable.HashSet[Foo] with mutable.SynchronizedSet[Foo] \/\/ &lt;- Mixin works new mutable.TreeSet[Foo]()(orderByCount) with mutable.SynchronizedSet[Foo] \/\/ Fail!The last line gives a<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/bdca3523d594811ce1c8f88cfe0f3f51?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nDocMax<br \/>\nexception reflection .net-assembly implicit<br \/>\nI am using the following to generate a method at runtime:System.Reflection.Assembly currentAssembly = System.Reflection.Assembly.GetExecutingAssembly(); System.CodeDom.Compiler.CompilerParameters compilerParams = new System.CodeDom.Compiler.CompilerParameters(); compilerParams.GenerateExecutable = false; compilerParams.GenerateInMemory = true; compilerParams.ReferencedAssemblies.Add(currentAssembly.Location); System.CodeDom.Compiler.CodeDomProvider provider = System.CodeDom.Compiler.CodeDomProvi<\/li>\n<\/ul>\n<p>Web site is in building<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Rafael c# matrix operator-keyword implicit I have this class:public class SmartTable : DataTable {public string this[int Row, int Column] { &#8230; }public string this[int Row, string Column] { &#8230; } }and i want to add an implicit operator on THIS[,]then i could use:string s = smartT[a,b];orint i = smartT[a,b];I googled this but even I don&#8217;t [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4467","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4467","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4467"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4467\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4467"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4467"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4467"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}