Skip to content

Instantly share code, notes, and snippets.

View etorreborre's full-sized avatar
🏠
Working from home

Eric Torreborre etorreborre

🏠
Working from home
View GitHub Profile
scala> import scala.reflect.runtime.universe._
import scala.reflect.runtime.universe._
scala> def countImplicits(tp: Type): Int = tp.members.count(_.isImplicit)
countImplicits: (tp: reflect.runtime.universe.Type)Int
scala> countImplicits(typeOf[org.specs2.mutable.Specification])
res0: Int = 205
scala> countImplicits(typeOf[org.scalatest.Spec])
// No thank you re: scala 2.10.2 artifacts.
def plugin(m: ModuleID) = Defaults.sbtPluginExtra(m, "0.13", "2.10") excludeAll ExclusionRule("org.scala-lang")
libraryDependencies ++= Seq(
plugin("me.lessis" % "bintray-sbt" % "0.1.2"),
plugin("com.typesafe" % "sbt-mima-plugin" % "0.1.6")
)
[info] Compiling 1 Scala source to /Users/mth/home/art-of-stream-processing-workshop/scalaz-stream/target/scala-2.11/classes...
[error] Illegal index: 0 overlaps List((variable par1,LONG))
[error] locals: Map(1 -> List((variable par1,LONG)))
[error] one error found
[error] (compile:compile) Compilation failed
/**
* Do a 'balanced' reduction of `v`. Provided `f` is associative, this
* returns the same result as `v.reduceLeft(f)`, but uses a balanced
* tree of concatenations, which is more efficient for operations that
* must copy both `A` values to combine them in `f` - O(n*log n) rather than
* quadratic.
*
* Implementation uses a stack that combines the top two elements of the
* stack using `f` if the top element is more than half the size of the
* element below it.
object IO2a {
/*
The previous IO representation overflows the stack for some programs.
The problem is that `run`
*/
sealed trait IO[A] {
def flatMap[B](f: A => IO[B]): IO[B] =
FlatMap(this, (a: A) => Suspend { () => f(a) }) // note this returns immediately
import scodec.codecs
import scodec.bits.{BitVector,ByteVector}
import scalaz.stream.{Process1,Process}
object Unframing {
/**
* Break an input bytestream along frame boundaries. Input consists of a stream of frames,
* where each frame is just a number of bytes, encoded as an int32, followed by a packet of
* that many bytes. End of stream is indicated with a frame of size <= 0. Output stream is
class ext extends StaticAnnotation {
def macroTransform(annottees: Any*) = macro extension.impl
}
object extension {
def impl(c: Context)(annottees: c.Expr[Any]*): c.Expr[Any] = {
import c.universe._
annottees.map{ _.tree }.head match {
case q"def $name[..$tp](...$params): $ret = $b" =>
val Seq(Seq(thiz, rest @ _*), rest2 @ _*) = params

So what I understand to be your questions:

  1. What is a coherency problem?
  2. What does over constained code look like / cause?
  3. How do you lose your "desired" instance?

A way to step through understanding this problem:

  • Oh shit, If I have local type classes, I have to handle crazy wacky cases in my implementation, this will likely have performance and correctness implications (see Coherency.scala)
  • What happens if I close over constraint on construction? Oops if I close over it, I end up with OverConstrained code (see OverConstrainedCode.scala) and worse I still have coherency issues, and the ability to lose my intended behavious (LosingAnInstance.scala)
  • Oh wow, if I just don't do local type classes, by never define conflicting implicits, and ascribe a single type to each behaviour, everything is simple and just works.
@etorreborre
etorreborre / BugSpec.scala
Last active August 29, 2015 13:56 — forked from raronson/BugSpec
package com.ambiata.ivory.scoobi
import org.specs2._
import com.nicta.scoobi.Scoobi._
import com.nicta.scoobi.testing.mutable._
import com.nicta.scoobi.testing.SimpleJobs
import com.nicta.scoobi.testing.TestFiles._
import com.nicta.scoobi.testing.TempFiles
import scalaz.{DList => _, _}, Scalaz._
# Get yourself sbt-extras
# Or: brew install sbt
alias scalaz="sbt -sbt-create 'set libraryDependencies += \"org.scalaz\" %% \"scalaz-core\" % \"7.1.0-M4\"' 'set initialCommands := \"import scalaz._; import Scalaz._\"' 'console'"