Skip to content

Instantly share code, notes, and snippets.

Miles Sabin milessabin

Block or report user

Report or block milessabin

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View ambiguous.scala
object Utils {
type Id[t] = t
type Const[c] = [t] => c
}
import Utils._
class Instances[F[_[_]], T[_]]
trait Functor[F[_]]
@milessabin
milessabin / LocalTests.scala
Last active Oct 6, 2018
Setup for local integration (ie. compile pos/neg/run) tests for lampepfl/dotty
View LocalTests.scala
// local/localtests/test/localtests/LocalTests.scala
package localtests
import java.nio.file._
import java.util.stream.{ Stream => JStream }
import org.junit.{ AfterClass, Test }
import scala.collection.JavaConverters._
import scala.concurrent.duration._
View gist:5385e70f9bbf2f613dd62ffb5f8adf25
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%]
View gist:380648c78d3ad3ede06e3bac084e4328
-----------------------------
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)
@milessabin
milessabin / typelevelcps.scala
Created May 29, 2018
Using type level continuation passing style to rewrite a whitebox macro (which relies on fundep materialization) as a blackbox macro
View typelevelcps.scala
import scala.language.higherKinds
// Whitebox ...
trait Schema[T, R] {
def conv(t: T): R
}
object Schema {
// Whitebox macro: R is computed from T
implicit def mkSchema[T, R]: Schema[T, R] = ??? // macro ...
View compact.scala
// 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
shapeless-style derivation of a FunctorK (aka HFunctor) instance for an arbitrary product F-algebra
View functork.scala
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 / no-effect.scala
Created Mar 20, 2018
Side-effects are bad, right?
View no-effect.scala
// 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
}
}
You can’t perform that action at this time.