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
example.dot: | |
graph graphname { | |
a -> b -> c; | |
b -> d; | |
} | |
$ graph-easy example.dot example.txt | |
$ cat example.txt | |
+---+ |
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 Sql { | |
import scala.reflect.makro._ | |
import language.experimental.macros | |
case class Query[R](/*sql: String*/) | |
def execute[R](q: Query[R]): Seq[R] = sys.error("implement me") | |
def sqlImpl(c: Context)(s: c.Expr[String]): c.Expr[Any] = { | |
import c.universe._ |
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
scala> import org.kiama.rewriting.Rewriter._ | |
import org.kiama.rewriting.Rewriter._ | |
scala> trait Expr | |
defined trait Expr | |
scala> case class Constant(x: Int) extends Expr | |
defined class Constant | |
scala> case class Add(e1: Expr, e2: Expr) extends Expr |
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
/* | |
$do { | |
x <- foo | |
y <- bar | |
z <- baz | |
return x * y * z | |
} | |
Desugars into: |
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
assemble = function(g, v, a) { | |
return $do { | |
gin <- g | |
vermouth <- v | |
amaro <- a | |
return new Negroni(gin, vermouth, amaro) | |
} | |
} |
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
// Compilation time of each commented function on my machine (as repoted by sbt console). | |
// ********************************************************************** | |
// Test.scala | |
import shapeless._ | |
import syntax.singleton._ | |
object Test { | |
val r = | |
("k01" ->> 1) :: ("k02" ->> 1) :: ("k03" ->> 1) :: ("k04" ->> 1) :: ("k05" ->> 1) :: |
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
// Compilation time of each commented function on my machine (as repoted by sbt console). | |
// ********************************************************************** | |
// Test.scala | |
import shapeless._ | |
import syntax.singleton._ | |
object Test { | |
val r = | |
("k01" ->> 1) :: ("k02" ->> 1) :: ("k03" ->> 1) :: ("k04" ->> 1) :: ("k05" ->> 1) :: |
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
// Test3.scala | |
import shapeless._ | |
import syntax.singleton._ | |
object Test3 { | |
val r = | |
(k01 ->> 1) :: (k02 ->> 1) :: (k03 ->> 1) :: (k04 ->> 1) :: (k05 ->> 1) :: | |
(k06 ->> 1) :: (k07 ->> 1) :: (k08 ->> 1) :: (k09 ->> 1) :: (k10 ->> 1) :: | |
(k11 ->> 1) :: (k12 ->> 1) :: (k13 ->> 1) :: (k14 ->> 1) :: (k15 ->> 1) :: | |
(k16 ->> 1) :: (k17 ->> 1) :: (k18 ->> 1) :: (k19 ->> 1) :: (k20 ->> 1) :: |
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
// Singleton types as keys | |
r get "k01" // 1s was 1s | |
r get "k02" // 3s was 4s | |
r get "k03" // 5s was 7s | |
r get "k04" // 6s was 10s | |
r get "k05" // 7s was 12s | |
r get "k10" // 12s was 21s | |
r get "k20" // 16s was 30s | |
// Objects as keys |
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
// See https://gist.github.com/jonifreeman/6533463 | |
object TestExplicitRecordType { | |
import shapeless._, record._, syntax.singleton._ | |
object testF extends Poly1 { | |
implicit def atFieldType[K, V] = at[(K, V)] { | |
case (k, v) => k.toString | |
} | |
} | |