Skip to content

Instantly share code, notes, and snippets.

Avatar

Miles Sabin milessabin

View GitHub Profile
View match-types.scala
miles@tarski:~% cs launch scala3-repl
scala> trait A
| trait B
| type M[X] = X match
| case A => Int
| case B => String
|
// defined trait A
// defined trait B
@milessabin
milessabin / trait-instances-2.scala
Last active June 23, 2020 08:39
Constraining trait type parameters via a super class type parameter constraint ... different instances along different paths
View trait-instances-2.scala
import cats.{Applicative, Monad}
import cats.implicits._
abstract class Foo[+M[_[_]], F[_]](implicit val M: M[F])
trait Bar[F[_]] extends Foo[Applicative, F] { def bar = Applicative[F] }
trait Baz[F[_]] extends Foo[Monad, F] { def baz = Monad[F] }
class User[F[_]: Monad] extends Bar[F] with Baz[F]
object Test {
@milessabin
milessabin / trait-instances.scala
Last active June 23, 2020 08:40
Constraining a trait type parameter via a super class type parameter constraint
View trait-instances.scala
import cats.{Applicative, Monad}
import cats.implicits._
abstract class Foo[+M[_[_]], F[_]](implicit val M: M[F])
trait Bar[F[_]] extends Foo[Applicative, F] { def bar = Applicative[F] }
trait Baz[F[_]] extends Foo[Monad, F] { def baz = Monad[F] }
class User[F[_]: Monad] extends Bar[F] with Baz[F]
object Test {
View match-types.scala
/*
* Copyright (c) 2019 Miles Sabin
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
View tupletype.scala
def tupleType(tpes: List[Type]): Type = {
val PairType = typeOf[_ *: _] match {
case Type.IsAppliedType(tp) => tp.tycon
}
@tailrec
def nestedPairs(tpes: List[Type], acc: Type): Type = tpes match {
case Nil => acc
case hd :: tail => nestedPairs(tail, Type.AppliedType(PairType, List(hd, acc)))
}
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 October 6, 2018 18:26
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%]
pre-pr 3 50 9,176.00 [-9.87% +199.00%] 9,176.00 [-9.87%