Skip to content

Instantly share code, notes, and snippets.

View mandubian's full-sized avatar

Pascal Voitot mandubian

View GitHub Profile
@mandubian
mandubian / TEMPLATE.glsl
Created May 19, 2014 11:42 — 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.
@mandubian
mandubian / ButterflyWaveScrawler.glsl
Created May 19, 2014 11:48 — 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.
uniform float waves;
private def buildTypeAlias(api: TypingTransformApi)(monadTTpe: Type)(mtpe: TypeSymbol)(innerTpe: Type): (TypeSymbol, Tree) = {
val nm = c.fresh(monadTTpe.typeSymbol.name.decodedName.toString)
val tname = newTypeName(nm)
val termname = newTermName(nm)
val sym = newTypeSymbol(api.currentOwner, tname)
val tree = q"""{
type $tname[T] = ${monadTTpe.typeSymbol}[${mtpe.typeSymbol}, T]
object $termname {
def apply[T](t: $mtpe[${innerTpe.typeSymbol}[T]]): $tname[T] = ${monadTTpe.typeSymbol.companion}.apply[${mtpe.typeSymbol}, T](t)
@mandubian
mandubian / gist:d487b391b41ed6cdf3df
Created May 23, 2014 09:15
Any idea on how to make that typecheck?
private def buildMonadTypeAlias(api: TypingTransformApi)(monadTTpe: Type)(mtpe: Type)(innerTpe: Type): (TypeSymbol, Tree) = {
val nm = c.fresh(monadTTpe.typeSymbol.name.decodedName.toString)
val tname = newTypeName(nm)
val termname = newTermName(nm)
val sym = newTypeSymbol(api.currentOwner, tname).setInfo(typeBounds(definitions.NothingTpe, definitions.AnyTpe))
val tree = q"""{
type $tname[T] = ${monadTTpe.typeSymbol}[${mtpe.typeSymbol}, T]
object $termname {
def apply[T](t: ${mtpe.typeSymbol}[${innerTpe.typeSymbol}[T]]): $tname[T] = ${monadTTpe.typeSymbol.companion}.apply[${mtpe.typeSymbol}, T](t)
@mandubian
mandubian / gist:e8d2bc41bb25b4b78c7d
Created May 28, 2014 10:32
Any hint that could help me ?
// First I create this alias type tree
val aliasTypeTree = q"""{
type $typeName[T] = ...
object $termName {
def apply[T](t: ...): $typeName[T] = ...
}
}"""
// I first try to use previous alias type in a block of code
val tree1 = q """
@mandubian
mandubian / gist:55f8b1fb9f9bec2c0a99
Last active August 29, 2015 14:02
multi-layer implicit + type lambdas
scala> implicitly[MonadPlus[({ type m[A] = ListT[({ type l[B] = OptionT[Future, B] })#l, A] })#m]]
<console>:23: scalaz.this.ListT.listTMonadPlus is not a valid implicit value for scalaz.MonadPlus[[A]scalaz.ListT[[B]scalaz.OptionT[scala.concurrent.Future,B],A]] because:
hasMatchingSymbol reported error: polymorphic expression cannot be instantiated to expected type;
found : [F[_]]scalaz.MonadPlus[[α]scalaz.ListT[F,α]]
required: scalaz.MonadPlus[[A]scalaz.ListT[[B]scalaz.OptionT[scala.concurrent.Future,B],A]]
implicitly[MonadPlus[({ type m[A] = ListT[({ type l[B] = OptionT[Future, B] })#l, A] })#m]]
^
<console>:23: error: could not find implicit value for parameter e: scalaz.MonadPlus[[A]scalaz.ListT[[B]scalaz.OptionT[scala.concurrent.Future,B],A]]
implicitly[MonadPlus[({ type m[A] = ListT[({ type l[B] = OptionT[Future, B] })#l, A] })#m]]
scala> val toto = 5; val tata = "chboing"
toto: Int = 5
tata: String = chboing
scala> val qq = q"""{ "foo" : $toto, $tata : "bar" }"""
<console>:13: error: ';' expected but ',' found.
val qq = q"""{ "foo" : $toto, $tata : "bar" }"""
@mandubian
mandubian / gist:71deee51bc498c384c5e
Last active August 29, 2015 14:04
Forall2 universal quantifier with 2 type params
/** A universally quantified value */
trait Forall2[P[_, _]] {
def apply[A, B]: P[A, B]
}
object Forall2 extends Foralls2
trait Foralls2 {
/** Universal quantification by doubly negating an existential. */
type Not[A] = A => Nothing
@mandubian
mandubian / gist:e96a1a6531cb50158832
Created July 29, 2014 13:18
HMonoid : Monoid for heterogenous structures (and others too)... Dumb or interesting idea?
"ShapelessExt" should "try" in {
implicit class Rich[A](val a: A) {
def +[B](b: B)(implicit hm: HMonoid[A, B]) = hm.append(a, b)
}
// HList HMonoid
val s = (1 :: "string" :: HNil) + (true :: HNil)
s should equal (1 :: "string" :: true :: HNil)
trait APointer[U, A] extends DepFn1[A] { type Out <: U}
implicit def HListAPointer[A] = new APointer[HList, A] {
type Out = A :: HNil
def apply(a: A) = a :: HNil
}
scala> val t: Int :: HNil = implicitly[APointer[HList, Int]].apply(1)
type mismatch;