Skip to content

Instantly share code, notes, and snippets.

View milessabin's full-sized avatar

Miles Sabin milessabin

View GitHub Profile
[acyclic] --== Extracting dependencies for acyclic ==--
[acyclic] Fetching https://github.com/lihaoyi/acyclic.git
[acyclic] into /home/miles/projects/community-builds/clones-0.9.5/245e354ad2399f7a8e44b501df16710d5ca8e18e-acyclic
[acyclic] Took: 00h 00m 00.4s
[acyclic] Cloning /home/miles/projects/community-builds/clones-0.9.5/245e354ad2399f7a8e44b501df16710d5ca8e18e-acyclic
[acyclic] to /home/miles/projects/community-builds/target-0.9.5/extraction/d4f22467376ec652fb03d6c58593ba6d267adf39/projects/73e1fbbb9c28dd54a52679838829b3b71d4f9386
[acyclic] Took: 00h 00m 00.0s
[acyclic] Fetching /home/miles/projects/community-builds/clones-0.9.5/245e354ad2399f7a8e44b501df16710d5ca8e18e-acyclic
[acyclic] into /home/miles/projects/community-builds/target-0.9.5/extraction/d4f22467376ec652fb03d6c58593ba6d267adf39/projects/73e1fbbb9c28dd54a52679838829b3b71d4f9386
[acyclic] Took: 00h 00m 00.0s
miles@tarski:shapeless (master)% sbt -Dsbt.profile=2.12.x
[info] Loading global plugins from /home/miles/.sbt/0.13/plugins
[info] Loading project definition from /home/miles/projects/shapeless/project
[info] Set current project to root (in build file:/home/miles/projects/shapeless/)
> project coreJVM
[info] Set current project to core (in build file:/home/miles/projects/shapeless/)
> ++2.12.0-RC2
[info] Setting version to 2.12.0-RC2
[info] Reapplying settings...
[info] Set current project to core (in build file:/home/miles/projects/shapeless/)
@milessabin
milessabin / gist:c4b7285f40f7a1cc3593d93fa0ad3a02
Last active October 16, 2016 11:30
Intersecting both instances and syntax to resolve ambiguity
package demo
import scala.language.higherKinds
import scala.language.implicitConversions
trait Functor[F[_]] {
def map[A, B](fa: F[A])(f: A => B): F[B]
}
trait Monad[F[_]] extends Functor[F] {
import scala.language.higherKinds
trait Functor[F[_]] {
def map[A, B](fa: F[A])(f: A => B): F[B]
}
trait Traverse[F[_]] {
implicit val F: Functor[F]
}
tapply: (a -> b) -> a -> b
tapply ab a = ab a
foo: (tapply List Nat) --OK
foo = [1, 2, 3]
mkPair: a -> b -> (a, b)
mkPair a b = (a, b)
bar: (mkPair Nat String) -- Not OK
@milessabin
milessabin / gist:6c9c060cf5159563b722d49ce9ee103e
Last active July 26, 2017 20:42
Induction benchmark: vanilla scalac vs. scalac + proof of concept inductive solver
// Compiled with ./build/pack/bin/scalac -J-Xss4M -J-Xmx4G test/files/pos/inductive-implicits.scala
// HList scalac scalac +
// Size inductive heuristics
// 50 6 4
// 100 15 5
// 150 36 6
// 200 68 6
// 250 114 7
// 300 179 9
scala> def stuff(xs: ::[Int]): Int = xs.head
stuff: (xs: ::[Int])Int
scala> stuff(Nil)
<console>:13: error: type mismatch;
found : scala.collection.immutable.Nil.type
required: ::[Int]
stuff(Nil)
^
scala> def narrow[T <: Singleton](t: T): T {} = t
narrow: [T <: Singleton](t: T)T
scala> narrow(23)
res1: 23 = 23
scala> var x = narrow(42)
x: 42 = 42
scala>
### 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 / sip23.scala
Created July 5, 2016 22:50
SIP-23 redux ...
object Test {
def one[T <: 1](t: T): T = t
final val o = one(1)
o: 1
def narrow[T <: Singleton](t: T): T {} = t
final val fn0 = narrow(23)
fn0: 23
val n0 = narrow(23)