Skip to content

Instantly share code, notes, and snippets.

View milessabin's full-sized avatar

Miles Sabin milessabin

View GitHub Profile
This file has been truncated, but you can view the full file.
miles@tarski:perf_tester (topic/miles-byname-implicits)% java -jar target/scala-2.12/perf_tester-assembly-0.1.jar -s /home/miles/projects/scala -r results -a corpus/scala-library -c miles-byname-implicits --user miles -i 50 -p 3
Output logging to /home/miles/projects/perf_tester/results/miles/miles-byname-implicits
ALL
Run Name Cycle samples Wall time (ms) All Wall time (ms) CPU(ms) Idle time (ms) Allocated(MBs)
pre-pr 1 50 9,332.00 [-10.92% +203.33%] 9,332.00 [-10.92% +203.33%] 9,188.06 [-10.64% +196.26%] 0.00 [ NaN% NaN%] 2,743.61 [-0.38% +6.58%]
pre-pr 2 50 9,088.94 [-10.42% +192.67%] 9,088.94 [-10.42% +192.67%] 8,959.18 [-10.03% +185.47%] 0.00 [ NaN% NaN%] 2,745.65 [-0.51% +6.81%]
pre-pr 3 50 9,176.00 [-9.87% +199.00%] 9,176.00 [-9.87%
-----------------------------
ALL
Run Name Cycle samples Wall time (ms) All Wall time (ms) CPU(ms) Idle time (ms) Allocated(MBs)
pre-pr 1 30 9,830.23 [-13.87% +183.84%] 9,830.23 [-13.87% +183.84%] 9,644.07 [-13.42% +178.31%] 0.00 [ NaN% NaN%] 2,775.16 [-0.65% +6.12%]
pr 1 30 9,818.50 [-14.81% +186.90%] 9,818.50 [-14.81% +186.90%] 9,642.10 [-14.13% +181.26%] 0.00 [ NaN% NaN%] 2,762.69 [-0.67% +7.13%]
jason-feedback 1 30 9,805.13 [-14.34% +184.80%] 9,805.13 [-14.34% +184.80%] 9,617.57 [-13.61% +179.12%] 0.00 [ NaN% NaN%] 2,760.19 [-0.62% +6.94%]
-----------------------------
ALL
Run Name Cycle samples Wall time (ms) All Wall time (ms) CPU(ms)
// Current Scala 2
trait Concat[A, B] {
type Result
def apply(a: A, b: B): Result
}
object Concat {
def apply[A, B](a: A, b: B)(implicit cab: Concat[A, B]): cab.Result = cab(a, b)
implicit def hnil[B]: Concat[HNil, B] { type Result = B } = new Concat[HNil, B] {
@milessabin
milessabin / functork.scala
Created May 11, 2018 16:16
shapeless-style derivation of a FunctorK (aka HFunctor) instance for an arbitrary product F-algebra
import scala.language.{ higherKinds, implicitConversions }
object Defns {
type Id[T] = T
type ApplyTo[T] = { type λ[F[_]] = F[T] }
type Const1[T] = { type λ[F[_]] = T }
// Natural transform
trait ~>[F[_], G[_]] {
def apply[T](ft: F[T]): G[T]
@milessabin
milessabin / gist:8833a1dbf7e8245b30f8
Last active April 16, 2018 02:39
Now in shapeless 2.1.0-SNAPSHOT: "shapeless.the" an enhanced alternative to "Predef.implicitly".
// Used as a term `the[T]` yields the unique implicit value of type `T` in the current
// implicit scope, if any. It is a compile time error if there is no such value. Its
// primary advantage over `Predef.implicitly` is that it will preserve any refinement that
// the implicit definition has, resulting in more precisely typed, and hence often more
// useful, values,
scala> trait Foo { type T ; val t: T }
defined trait Foo
scala> implicit val intFoo: Foo { type T = Int } = new Foo { type T = Int ; val t = 23 }
@milessabin
milessabin / no-effect.scala
Created March 20, 2018 10:38
Side-effects are bad, right?
// What output does this yield? What should it? (try with either 2.12.x or 2.13.x)
// (spoiler: https://github.com/scala/bug/issues/10788)
object Test {
class Box[T](t: T) {
def foo: T = {
println("effect")
t
}
}
@milessabin
milessabin / gist:6256495
Last active March 10, 2018 02:26
Path dependent types with an implicit prefix. We can infer the singleton type prefix of a path dependent type and then implicitly summon the unique value of that singleton type.
Welcome to Scala version 2.10.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_21).
Type in expressions to have them evaluated.
Type :help for more information.
scala> class Prefix { class Dep { type P = Prefix.this.type } }
defined class Prefix
scala> val (p1, p2) = (new Prefix, new Prefix)
p1: Prefix = Prefix@2212c414
p2: Prefix = Prefix@7e070e85
### Keybase proof
I hereby claim:
* I am milessabin on github.
* I am milessabin (https://keybase.io/milessabin) on keybase.
* I have a public key whose fingerprint is 87D4 DCA4 07A5 556C 0BAD D01F 420D 4BEE 9FA4 7A44
To claim this, I am signing this object:
@milessabin
milessabin / shapeless-session.txt
Created April 1, 2016 12:29
shapeless on the Ammonite REPL with no dependencies other than an installed JDK. Many thanks to @przemekpokrywka for the idea, @alxarchambault for Coursier and @li_haoyi for Ammonite.
miles@frege:~$ ./shapeless.sh
Loading...
Welcome to the Ammonite Repl 0.5.2
(Scala 2.11.7 Java 1.8.0_51)
@ val l = 23 :: "foo" :: true :: HNil
l: Int :: String :: Boolean :: HNil = ::(23, ::("foo", ::(true, HNil)))
@
import scala.language.higherKinds
class Cartesian[F[_]] {
trait Arbitrary1
trait Arbitrary2
implicit val fa1: F[Arbitrary1] = null.asInstanceOf
implicit val fa2: F[Arbitrary2] = null.asInstanceOf
class QED
implicit def proof(implicit fa12: F[(Arbitrary1, Arbitrary2)]): QED = null
}