Skip to content

Instantly share code, notes, and snippets.

View xeno-by's full-sized avatar

Eugene Burmako xeno-by

View GitHub Profile
18:15 ~/Projects/6240 (ticket/6240)$ ant test.osgi
Buildfile: /Users/xeno_by/Projects/6240/build.xml
desired.jars.uptodate:
boot:
init:
[artifact:dependencies] [WARNING] POM for 'biz.aQute:bndlib:pom:1.43.0:compile' is invalid.
[artifact:dependencies]
@xeno-by
xeno-by / gist:6156001
Created August 5, 2013 13:43
Macro paradise 2.0.0-SNAPSHOT
~/210x $ scala -Xshow-phases
phase name id description
---------- -- -----------
parser 1 parse source into ASTs, perform simple desugaring
macroparadise 2 let our powers combine
namer 3 resolve names, attach symbols to named trees in paradise
packageobjects 4 load package objects in paradise
typer 5 the meat and potatoes: type the trees in paradise
...
// TreeCreator is conceptually a dependent function that:
// 1) Takes a universe-bound mirror
// 2) Produces a tree from the same universe
// So I would like to write it as follows (imaginary syntax)
// e.g. as per this proposal: http://blaisorbladeprog.blogspot.de/2013/01/flexible-implicits-from-agda-for-scala.html
abstract class TreeCreator {
def apply[[u: Universe]](m: u.Mirror): u.Tree
}
scala> class Foo[B[_], T]
defined class Foo
scala> def test[B[_]](implicit tt: TypeTag[B[_]]) = typeOf[Foo[B, _]]
<console>:30: error: No TypeTag available for Foo[B, _]
def test[B[_]](implicit tt: TypeTag[B[_]]) = typeOf[Foo[B, _]]
^
sealed abstract class Character
case object Violent extends Character
case object Weak extends Character
case object Clever extends Character
case object Dumb extends Character
case object Stupid extends Character
case class Person (
id: DId,
name: String
@xeno-by
xeno-by / gist:5967900
Created July 10, 2013 16:38
Macro-powered structural types
import scala.annotation.StaticAnnotation
import scala.reflect.macros.Macro
import language.experimental.macros
class body(tree: Any) extends StaticAnnotation
trait Macros extends Macro {
import c.universe._
def selFieldImpl = {
import scala.reflect.macros.Context
import language.experimental.macros
object Macros {
def impl1(c: Context) = {
import c.universe._
q"new { def x = macro Macros.impl2 }"
}
def foo = macro impl1
def RefTree(qual: Tree, sym: Symbol) = self.RefTree(qual, sym.name) setSymbol sym
val protocol: Consumer[ByteBuffer, Message] =
for {
hdr <- msgHdr
(body, sha) <- bodyProcessor(hdr) zip sha1sum
if sha == hdr.sha
} yield Message(hdr,body)
withFile(file) { c =>
val bytes: Producer[ImmutableBuffer[Byte,Read]] =
bytechannels.read_channel_bytes(c, directBuffers=true)
val chars = Producer[ImmutableBuffer[Char,Read]] =
bytes convert charsets.decoder()
val wordCount: Consumer[ImmutableBuffer[Char, Read], Long] =
charchannels.words convert utils.counter
val lineCount: Consumer[ImmutableBuffer[Char, Read], Long] =
charchannels.lines convert utils.counter
val allCount: Consumer[ImmutableBuffer[Char,Read], String] =