Skip to content

Instantly share code, notes, and snippets.

View paulp's full-sized avatar
🤫

Paul Phillips paulp

🤫
  • CAZ, Inc.
  • Cascadia Autonomous Zone
View GitHub Profile
@paulp
paulp / macroImpl.scala
Last active September 2, 2016 16:20
Indirect compile-time literal types
class MacroBundle(val c: Context) {
/* etc */
/** Typecheck singleton types so as to obtain indirectly
* available known-at-compile-time values.
*/
object Const {
def unapply(tp: Type): Option[Constant] = tp match {
case ConstantType(c) => Some(c)
case SingleType(_, sym) => unapply(c.typecheck(q"$sym").tpe)
@paulp
paulp / typelevel.sh
Last active August 28, 2016 19:00
A script for running typelevel scala.
#!/usr/bin/env bash
#
run () { echo >&2 "$@" && "$@"; }
typelevel () {
coursier fetch org.typelevel:scala-compiler:2.11.8 | paste -sd: -
}
ammonite () {
coursier fetch com.lihaoyi:ammonite_2.11.8:0.7.2 | egrep -vw 'scala-lang' | paste -sd: -
package xquasar
trait Deps {
def bundleVersion = "-q00"
def specsVersion = "3.8.4" + bundleVersion
def refinedVersion = "0.5.0" + bundleVersion
def disciplineVersion = "0.5" + bundleVersion
def scalazSpecsVersion = "0.4" + bundleVersion
def monocleVersion = "1.2.2" + bundleVersion
@paulp
paulp / failures
Last active August 12, 2016 22:37
testing coursier as a drop-in replacement
origin https://github.com/gitbucket/gitbucket (fetch)
origin https://github.com/gitbucket/gitbucket (push)
Aug 08 18:50:38 Downloaded https://repo1.maven.org/maven2/com/sun/mail/javax.mail/1.5.2/javax.mail-1.5.2.jar
Aug 08 18:50:38 Downloaded https://repo1.maven.org/maven2/com/typesafe/slick/slick_2.11/2.1.0/slick_2.11-2.1.0.jar
Aug 08 18:50:38 [info] Fetched artifacts of io.github.gitbucket:gitbucket_2.11:4.3.0
Aug 08 18:50:40 coursier.ResolutionException: 1 not found https://repo1.maven.org/maven2/org/apache/sshd/apache-sshd/1.2.0/apache-sshd-1.2.0.jar
Aug 08 18:50:40 [error] (*:update) coursier.ResolutionException: 1 not found https://repo1.maven.org/maven2/org/apache/sshd/apache-sshd/1.2.0/apache-sshd-1.2.0.jar
Aug 08 18:50:40 [error] Total time: 10 s, completed Aug 8, 2016 6:50:40 PM
ch.qos.logback:logback-classic:1.1.7
com.chuusai:shapeless_2.11:2.3.1
com.github.julien-truffaut:monocle-core_2.11:1.2.2
com.github.julien-truffaut:monocle-macro_2.11:1.2.2
com.github.scopt:scopt_2.11:3.5.0
com.github.tototoshi:scala-csv_2.11:1.3.1
com.slamdata:matryoshka-core_2.11:0.11.1
com.slamdata:pathy-argonaut_2.11:0.2.1
com.slamdata:pathy-core_2.11:0.2.1
eu.timepit:refined_2.11:0.5.0
% sbtx core/test:dependencyTree
[info] Loading project definition from /s/scala/quasar/project/project
[info] Loading project definition from /s/scala/quasar/project
[info] Set current project to root (in build file:/s/scala/quasar/)
[info] Updating {file:/s/scala/quasar/}ejson...
[info] Updating {file:/s/scala/quasar/}effect...
[info] Resolving jline#jline;2.12.1 ...
[info] Done updating.
[info] Resolving org.scalaz#scalaz-concurrent_2.11;7.2.4 ...
[warn] There may be incompatibilities among your library dependencies.
@paulp
paulp / omg.scala
Created July 19, 2016 18:31
scala is bad.
object Main {
val s1 = Set[BigDecimal](-4.872401723124452E9, 0, 1.1752011936438014, 8.696374707602505E17, -1.1752011936438014)
val s2 = Set[Double] (-4.872401723124452E9, 0, 1.1752011936438014, 8.696374707602505E17, -1.1752011936438014)
val s3: Set[BigDecimal] = s2 map (d => BigDecimal(d))
def main(args: Array[String]): Unit = {
/* false */ println(s1 == s2)
/* true */ println(s1 == s3)
/* false */ println(s2 == s3)
/* true */ println(s1.toSeq.sorted == s2.toSeq.sorted)
val d1: JNum = JNum(123.455555555555)
val d2: JNum = JNum(123.456)
val d3: JNum = JNum(123.4560000000923)
val d4: JNum = JNum(-1.000000472)
val d5: JNum = JNum(-1.0)
val d6: JNum = JNum(-0.99999999999)
val d7: JNum = JNum(3333333.0)
val d8: JNum = JNum(0.0)
val d9: JNum = JNum(0.00000001)
package p
sealed trait Bar
final case object Oops extends Bar
final case class Foo(s: String) extends Bar
object Foo {
def apply(x: Double): Bar = if (x.isNaN) Oops else Foo("double")
def apply(x: BigDecimal): Foo = Foo("BigDecimal")
}
package p
sealed trait Bar
final case object Oops extends Bar
final case class Foo(s: String) extends Bar
object Foo {
def apply(x: Double): Bar = if (x.isNaN) Oops else Foo("double")
def apply(x: BigDecimal): Foo = Foo("BigDecimal")
}