Skip to content

Instantly share code, notes, and snippets.

View milessabin's full-sized avatar

Miles Sabin milessabin

View GitHub Profile
@puffnfresh
puffnfresh / Test.scala
Last active January 4, 2016 00:19
Minimised scalac crash.
import scalaz._
import Scalaz._
import scalaz.effect._
object Test {
implicit def eitherTMonadIO[M[_], E](implicit M: MonadIO[M]): MonadIO[({type l[A]=EitherT[M, E, A]})#l] = ???
def x = for {
_ <- true whenM IO.putStrLn("World").liftIO[({type e[A]=EitherT[IO, String, A]})#e]
} yield ()
@puffnfresh
puffnfresh / scalaz.sh
Created December 20, 2013 03:24
Easy scalaz REPL!
# Get yourself sbt-extras
# Or: brew install sbt
alias scalaz="sbt -sbt-create 'set libraryDependencies += \"org.scalaz\" %% \"scalaz-core\" % \"7.1.0-M4\"' 'set initialCommands := \"import scalaz._; import Scalaz._\"' 'console'"
@travisbrown
travisbrown / recursive-vampire.scala
Last active December 19, 2015 17:49
Tested only in Paradise 2.11.0-SNAPSHOT.
import scala.annotation.StaticAnnotation
import scala.collection.mutable.{ Map => MMap }
import scala.language.experimental.macros
import scala.reflect.macros.Context
class body(tree: Any) extends StaticAnnotation
object Macros {
val trees = MMap.empty[String, c.Tree forSome { val c: Context }]
// pseudo-code mixing quasiquotes with 2.10 syntax, don't worry ;)
Macros.doit( "a" -> ("b", "c"), "a1" -> ("b1", "c1") )
object Macros {
def doit(xs: Any*) = macro doitImpl
def doitImpl(c: Context)(xs: c.Expr[Any]*) = {
import c.universe._
val fields = xs.toList map {
@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
@larsrh
larsrh / sequencer.scala
Last active December 16, 2015 18:30
Sequence `HList`s
import shapeless._
import scalaz._
import scalaz.syntax.apply._
sealed trait UnapplyFirst[F[_], L <: HList] {
def TC: Applicative[F]
}
@aztek
aztek / FRP.scala
Last active December 16, 2015 03:59
Trivial FRP for Scala with scala-idioms
import idioms._ // http://github.com/aztek/scala-idioms
trait Cell[T] {
def ! : T
def := (value: T) { throw new UnsupportedOperationException }
}
val frp = new Idiom[Cell] {
def pure[A](a: ⇒ A) = new Cell[A] {
private var value = a
@raichoo
raichoo / gist:5371927
Last active May 12, 2016 18:43
Playing with propositional equality in Scala (+inductive proof)
import scala.language.higherKinds
/*
* The usual peano numbers with addtion and multiplication
*/
sealed trait Nat {
type Plus[N <: Nat] <: Nat
type Mult[N <: Nat] <: Nat
}
@paulp
paulp / transcript
Last active December 15, 2015 13:09
scala> class Bippy(xs: List[Int]) extends improving.TypesafeProxy(xs) { def isEmpty = true }
defined class Bippy
scala> val bippy = new Bippy(1 to 10 toList)
bippy: Bippy = List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
scala> bippy.slice(3, 7)
[proxy] $line4.$read.$iw.$iw.bippy.slice(3, 7)
res1: List[Int] = List(4, 5, 6, 7)