Skip to content

Instantly share code, notes, and snippets.

View mandubian's full-sized avatar

Pascal Voitot mandubian

View GitHub Profile
@mandubian
mandubian / gist:8955241
Created February 12, 2014 13:07
Reads/Writes for a simple AST
import play.api.libs.json._
import play.api.libs.functional.syntax._
sealed trait Parent {
val typ: String
}
case class Foo(blabla: Long, override val typ: String = "foo") extends Parent
@mandubian
mandubian / gist:9068094
Created February 18, 2014 10:14
Scalaz Task.async stack-safety?
def task = Task.async{ cb: (Throwable \/ Int => Unit) =>
try {
cb(right(42))
} catch { case t:Throwable => cb(left(t))} }
def repeat(nb: Int) = {
def step(i: Int, c: Task[Int]): Task[Int] = {
if(i<nb) c.flatMap{ _ => step(i+1, task) }
else c
}
@mandubian
mandubian / gist:9320732
Created March 3, 2014 08:26
Chaining 2 server/client(s) prevent gives random results...
import java.net.InetSocketAddress
import scalaz.{-\/, \/, \/-}
import scalaz.concurrent.Task
import scalaz.stream._
import scala.concurrent.duration._
import ReceiveY._
import scala.concurrent.SyncVar
object Server {
@mandubian
mandubian / gist:9365064
Last active August 29, 2015 13:57
Look at the awakeEvery on client... only first element of the process is emitted and no other...
import Process._
import java.net.InetSocketAddress
import scala.Some
import scala.concurrent.SyncVar
import scala.util.Random
import scalaz.-\/
import scalaz.\/
import scalaz.\/-
import scalaz.concurrent.Task
import scala.concurrent.duration._
@mandubian
mandubian / gist:10476640
Last active August 29, 2015 13:59
How to determine a Tree of type `Some[Int]` can be seen as weakTypeTag[Option[_]] in this macro?
// I have a macro
def macmac[M[_], T] = macro macmacImpl
def macmacImpl[M[_], T: c.WeakTypeTag](c: Context)
(body: c.Expr[T])
(implicit mw: c.WeakTypeTag[M[_]]): c.Expr[M[T]]
// somewhere in the macro, it's calling this function
def myFun[M[_], T](block: Tree)(mType: WeakTypeTag[M[_]], tType: WeakTypeTag[T]): Tree = {
@mandubian
mandubian / gist:10878369
Last active August 29, 2015 13:59
Do you see why this slains the compiler?
import scala.reflect.macros.Context
import scala.reflect.api.Universe
object Foo {
def doit[T](t: T) = ???
def bar[T](body: T): Option[T] = macro barImpl[T]
def barImpl[T: c.WeakTypeTag](c: Context)(body: c.Expr[T]): c.Expr[Option[T]] = {
import c.universe._, c.internal._, decorators._, Flag._
@mandubian
mandubian / gist:11373329
Last active August 29, 2015 14:00
Trying to re-use custom type def in a macro
//I have a type with 2 types params
class Toto[M[_], T]
// I make a Monad of Future of it using lambda-type
implicit val TotoMonad = Monad[({ type l[T] = Toto[Future, T]})#l]{...}
// then in my macro I want to create a type alias to { type l[T] = Toto[Future, T]})#l] and call the implicit monad
val mType: Type = ...
val sym = newTypeSymbol(api.currentOwner, "FooToto")
@mandubian
mandubian / gist:11394893
Created April 29, 2014 09:15
Any idea to make this typecheck? How should I declare T to make it usable in this expression?
val rhs = api.typecheck(q"type $l[T] = _root_.scalaz.OptionT[scala.concurrent.Future, T]")
println("RHS:" + rhs)
// gives
RHS:type Tata[T] = scalaz.OptionT[scala.concurrent.Future,<error>]
// and my global macro then fails with (even if I don't put rhs in my tree)
[error] not found: type T
@mandubian
mandubian / CrazyParametricFun.glsl
Created May 19, 2014 08:04 — forked from glslioadmin/TEMPLATE.glsl
GLSL.io Transition (v1)
#ifdef GL_ES
precision highp float;
#endif
uniform sampler2D from, to;
uniform float progress;
uniform vec2 resolution;
// default a = 4
uniform float a;
// default b = 1
@mandubian
mandubian / TEMPLATE.glsl
Created May 19, 2014 11:41 — forked from glslioadmin/TEMPLATE.glsl
GLSL.io Transition (v1)
#ifdef GL_ES
precision highp float;
#endif
uniform sampler2D from, to;
uniform float progress;
uniform vec2 resolution;
// default amplitude = 1.0
uniform float amplitude;
// default waves = 30.