This file contains hidden or 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://github.com/gseitz/Lensed | |
case class CoState[A, B](put: A => B, pos: A) | |
object CoState { | |
type Store[A, B] = CoState[A, B] | |
} | |
// fused get/set | |
case class Lens[A, B](lens: A => CoState[B, A]) { |
This file contains hidden or 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
#!/bin/sh | |
# Just copy and paste the lines below (all at once, it won't work line by line!) | |
# MAKE SURE YOU ARE HAPPY WITH WHAT IT DOES FIRST! THERE IS NO WARRANTY! | |
function abort { | |
echo "$1" | |
exit 1 | |
} | |
set -e |
This file contains hidden or 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
trait TF { | |
type Apply[A] | |
} | |
type Curry2[F[_, _]] = TF { type Apply[X] = TF { type Apply[Y] = F[X, Y] } } | |
type Curry3[F[_, _, _]] = TF { type Apply[X] = Curry2[(TF { type Apply[Y, Z] = F[X, Y, Z] })#Apply] } | |
// ... | |
type CurriedMap = Curry2[Map] | |
val x: CMap#Apply[String]#Apply[Int] = Map("x" -> 1, "y" -> 1) //It is valid code. |
This file contains hidden or 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
:power | |
import java.io._ | |
import scala.tools.nsc.io.AbstractFile | |
def save(af: AbstractFile, dir: File) { | |
val f = new File(dir, af.name) | |
if (af.isDirectory) { | |
f.mkdirs() | |
af.par.foreach(a => save(a, f)) |
This file contains hidden or 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
trait Nat { | |
type IsZero <: Bool | |
type Prev <: Nat | |
type Divisable[A <: Nat] = DivisableImpl[A, A] | |
type DivisableImpl[A <: Nat, B <: Nat] <: Bool | |
} | |
trait Z extends Nat { | |
type IsZero = True | |
type Prev = Nothing |
This file contains hidden or 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
import twitter4j._ | |
import conf._ | |
/* build.sbt | |
scalaVersion := "2.9.1" | |
libraryDependencies ++= Seq( | |
"org.twitter4j" % "twitter4j-core" % "2.2.5", | |
"org.twitter4j" % "twitter4j-stream" % "2.2.5" |
This file contains hidden or 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
/** GADTs in Scala and their limitations */ | |
/** Background: what is an algebraic data type (ADT) ? | |
* ADT: (possibly) recursive datatype with sums and products | |
* In scala - a trait with case classes (case class is product, subtyping is sum) | |
*/ | |
/** Motivation: untyped embedded DSL doesn't prevent nonsensical expressions */ | |
sealed trait Expr { | |
def apply(other: Expr) = Ap(this, other) |
This file contains hidden or 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
import unfiltered.request._ | |
import unfiltered.response._ | |
import scala.xml._ | |
case class Xml(nodes: NodeSeq) | |
extends ComposeResponse(TextXmlContent ~> ResponseString(nodes.toString)) | |
// Usage | |
def intent = { | |
case GET(Path(Seg("hello" :: name :: Nil))) => { |
This file contains hidden or 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
trait Semigroup_ { | |
type F | |
def append(a: F, b: => F): F | |
} | |
trait Monoid_ extends Semigroup_ { | |
def zero: F | |
} | |
trait Functor_ { |
This file contains hidden or 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
import scalaz._ | |
import Scalaz._ | |
import scala.util.parsing.combinator._ | |
object KanjiNumberParser extends RegexParsers { | |
def one = "一" ^^ { _ => 1L } | |
def two = "二" ^^ { _ => 2L } | |
def three = "三" ^^ { _ => 3L } | |
def four = "四" ^^ { _ => 4L } | |
def five = "五" ^^ { _ => 5L } |