This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package cats | |
import cats.macros.Tags | |
object Tag { | |
type @@[A, T] = Tags.Tagged[A, T] | |
implicit class TagOps[A](a: A) { | |
def tag[T]: A @@ T = macro Tags.tagMacro[A, T] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Fast, accurate, generic, compatible: tensions around Scala's number types | |
Working with numbers in Scala can be a bit awkward. The number types are affected by | |
(and motivate) some of the weirder parts of Scala language and library: AnyVal types, | |
Arrays, Manifests, specialization, and type classes like Numeric. On the one hand, we | |
want operations on numbers to be as fast as Java operations on primitives. On the | |
other hand, Scala is an opportunity to do better than Java, especially with regard to | |
ad-hoc polymorphism, precision and power. This talk explores the problems, tensions and | |
opportunities the community faces as we evolve language and surrounding libraries. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@tailrec | |
def collapse[A](as:List[A])(f:(A, A) => A):Option[A] = as match { | |
case Nil => None | |
case a :: Nil => Some(a) | |
case as => collapse(pairwise(as, Nil)(f))(f) | |
} | |
@tailrec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import random | |
import sys | |
if __name__ == "__main__": | |
args = sys.argv[1:] | |
if args: | |
need = int(args[0]) | |
f = open(args[1], 'r') if len(args) > 1 else sys.stdin | |
else: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# A more capable sbt runner, coincidentally also called sbt. | |
# Author: Paul Phillips <paulp@typesafe.com> | |
# this seems to cover the bases on OSX, and someone will | |
# have to tell me about the others. | |
get_script_path () { | |
local path="$1" | |
[[ -L "$path" ]] || { echo "$path" ; return; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.{specialized => spec} | |
class Foo[@spec(Int) A](val a:A) { | |
def sink(x:A) = () | |
def bar[@spec(Int) B](b:B):Int = { | |
sink(a) | |
99 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait WithContext { | |
var ctx = null | |
def setContext(c:Context): Unit = if (ctx == null) { | |
ctx = c | |
} else { | |
sys.error("already set") | |
} | |
def fromContext[T](k:String):T = if (ctx == null) { | |
sys.error("premature access") | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.math._ | |
object Main { | |
def main(args:Array[String]) { | |
val a = LongComplex(13, 0) | |
val b = LongComplex(6, 2) | |
//println(a) | |
//println(b) | |
val c = a + b | |
//println(c) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object Util { | |
def unsigned(n:Byte) = (n + 0x100) & 0xFF | |
def unsigned(n:Short) = (n + 0x10000) & 0xFFFF | |
def b2i(a:Byte, b:Byte): Int = | |
(a<<8) + unsigned(b) | |
def b3i(a:Byte, b:Byte, c:Byte): Int = | |
(a<<16) + (b<<8) + unsigned(c) | |
def b4i(a:Byte, b:Byte, c:Byte, d:Byte): Int = | |
(a<<24) + (b<<16) + (c<<8) + unsigned(d) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[error] /home/erik/spire/src/main/scala/spire/buffer/Immutable.scala:33: ambiguous implicit values: | |
[error] both method manifest in class Reversed of type => Manifest[A] | |
[error] and value evidence$7 in class Reversed of type Manifest[A] | |
[error] match expected type Manifest[A] |