Skip to content

Instantly share code, notes, and snippets.

@milessabin
milessabin / conversions.scala
Created June 15, 2011 14:29
Code from my talk on representing polymorphic function values using type classes at the Scala eXchange ... full blog post to follow on http://www.chuusai.com/blog.
object Tuples {
import HLists._
implicit def tuple1ToHList[A](t : Product1[A]) = new { def hlisted : A :: HNil = t._1 :: HNil }
implicit def tuple2ToHList[A, B](t : Product2[A, B]) = new { def hlisted : A :: B :: HNil = t._1 :: t._2 :: HNil }
implicit def tuple3ToHList[A, B, C](t : Product3[A, B, C]) = new { def hlisted : A :: B :: C :: HNil = t._1 :: t._2 :: t._3 :: HNil }
implicit def hListToTuple1[A](h : A :: HNil) = new { def tupled : Tuple1[A] = Tuple1(h.head) }
implicit def hListToTuple2[A, B](h : A :: B :: HNil) = new { def tupled : (A, B) = (h.head, h.tail.head) }
implicit def hListToTuple3[A, B, C](h : A :: B :: C :: HNil) = new { def tupled : (A, B, C) = (h.head, h.tail.head, h.tail.tail.head) }
@dcsobral
dcsobral / SBT.sublime-build
Created February 23, 2012 18:31 — forked from jboner/SBT.sublime-build
Sublime Editor SBT build setup
{
"cmd": ["sbt-no-color test"],
"file_regex": "^\\[error\\] ([.a-z_A-Z0-9/-]+[.]scala):([0-9]+):",
"selector": "source.scala",
"working_dir": "${project_path:${folder}}",
"shell": "true"
}
import scala.reflect.makro.Context
object Macros {
def trace[A](expr: A) = macro traceImpl[A]
def traceImpl[A: c.TypeTag](c: Context)(expr: c.Expr[A]): c.Expr[A] = {
import c.universe._
// stand-in for the real type of the traced sub expression.
// This lets us conveniently splice this type into the
@tonymorris
tonymorris / ListZipper.scala
Created August 29, 2012 01:15
List Zipper
case class ListZipper[+A](lefts: List[A], x: A, rights: List[A]) {
def map[B](f: A => B): ListZipper[B] =
sys.error("todo")
// map with zipper context
def coFlatMap[B](f: ListZipper[A] => B): ListZipper[B] =
sys.error("todo")
def findRight(p: A => Boolean): Option[ListZipper[A]] =
sys.error("todo")
19:07 ~/Projects/Kepler_typemacros/sandbox (topic/typemacros)$ scalac Macros.scala
19:07 ~/Projects/Kepler_typemacros/sandbox (topic/typemacros)$ scala -cp .
Welcome to Scala version 2.10.1-20121120-175733-b60f5bcf2c (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_37).
Type in expressions to have them evaluated.
Type :help for more information.
scala> class C extends AnyRef with Macros.Foo[Int]("2")
defined class C
scala> new C().hello
/** Constructing "singleton types" from compile-time literals
*
* val x = Example.foo(42)
* val y: x.T = 42 // compiles
* val z: x.T = 43 // doesn't
*
*/
package s
import scala.language.experimental.macros
@poetix
poetix / builder.scala
Created January 15, 2013 12:26
Dynamic / Monadic object builder round 2
package com.youdevise.lofty
import org.specs2.mutable._
import scala.language.dynamics
import scala.language.reflectiveCalls
import scalaz._
import Scalaz._
import scala.reflect.runtime.universe._
trait Builder[T] {
@ymasory
ymasory / scala-irc
Last active August 30, 2017 21:16
List of all Scala-related IRC channels.
Please help compile a list of all Scala-related IRC rooms.
All of these channels are on Freenode.
#akka | concurrency & distribution framework
#argonaut | json library
#fp-in-scala | the book Functional Programming in Scala
#geotrellis | geoprocessing library
#indyscala | regional scala group
#json4s | json library
@jboner
jboner / SBT.sublime-build
Created May 6, 2011 09:47
Sublime Editor SBT build setup
{
"cmd": ["sbt-no-color compile"],
"file_regex": "^\\[error\\] ([.a-zA-Z0-9/-]+[.]scala):([0-9]+):",
"selector": "source.scala",
"working_dir": "${project_path:${folder}}",
"shell": "true"
}
@aloiscochard
aloiscochard / qsbt.sh
Last active March 5, 2018 21:34
QuickSBT - Launch SBT with support for generating /tmp/sbt.quickfix file for Vim
#!/usr/bin/env bash
############
# QuickSBT #
############
# Launch SBT with support for generating /tmp/sbt.quickfix file for Vim
# http://github.com/aloiscochard / https://gist.github.com/4698501
# Error format for SBT, and shortcut to open SBT quickfix file :