This file contains 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
package com.codecommit.misc | |
import scalaz._ | |
import scalaz.concurrent.Task | |
import scalaz.iteratee._ | |
import scalaz.stream._ | |
object conversion { | |
// TODO generalize to EmitterT |
This file contains 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 annotation.unchecked.uncheckedVariance | |
import reflect.runtime.universe.TypeTag | |
package object stuff { | |
// required for the better ??? operator | |
type MyTypeTag[+A] = TypeTag[A @uncheckedVariance] | |
def ???[A](implicit tag: MyTypeTag[A]): A = | |
throw new NotImplementedError(s"unimplemented value of type ${tag.tpe}") | |
} |
This file contains 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 Responder._ | |
import scalaz._ | |
object ResponderDemo extends Application { | |
import Scalaz._ | |
// -------------------------------------------------------------------------- | |
// Uses Responder (a continuation monad) to compose asynchronous functions. | |
// -------------------------------------------------------------------------- |
This file contains 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._ | |
val l = List(10, 20, 30, 40) | |
// loop from The Essence of the Iterator Pattern | |
// accumulates elements effectfully, but modifies elements purely and independently of accumulation | |
def loop[T[_]:Traverse, A, B](f: A => B, t: T[A]) = | |
t.traverse[({type λ[x] = State[Int,x]})#λ, (B, Int)](a => |
This file contains 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
/** | |
* I had a question directed at me, on how to encode the following scenario in Akka Actors, | |
* as for Scala Actors one would simply nest the receives. | |
* | |
* Recuirements are as follows: | |
* The first thing the actor needs to do, is to subscribe to a channel of events, | |
* Then it must replay (process) all "old" events | |
* Then it has to wait for a GoAhead signal to begin processing the new events | |
* It mustn't "miss" events that happen between catching up with the old events and getting the GoAhead signal | |
*/ |
This file contains 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
case class ElectricCar(b: Battery) { def batteryLevel = b.filledPercentage } | |
case class GasolineCar(g: GasTank) { def gasLevel = g.filledPercentage } | |
case class Battery(filledPercentage: Int) { def fill: Battery = Battery(100) } | |
case class GasTank(filledPercentage: Int) { def fill: GasTank = GasTank(100) } | |
trait Fills[C] { | |
def fill(car: C): C |
This file contains 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 http://lampsvn.epfl.ch/trac/scala/ticket/967. | |
// | |
// Gilles' fix causes the definition of Nat to be rejected with the error | |
// "Parameter type in structural refinement may not refer to a type member | |
// of that refinement". However we can work around the problem by | |
// quantifying out the problematic parameter type and reinstating it via | |
// a generalized type constraint. | |
type Num = { | |
type Rep |
This file contains 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._ | |
type List[A] = Forall[({type f[B] = ((A, B) => B, B) => B})#f] | |
val nil: Forall[List] = new Forall[List] { | |
def apply[A] = new List[A] { | |
def apply[B] = (c, n) => n | |
} | |
} |
This file contains 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
[user] | |
name = Paul Phillips | |
email = paulp@improving.org | |
[github] | |
user = $GITHUB_USER | |
token = $GITHUB_TOKEN | |
[clean] | |
requireForce = false | |
[grep] | |
lineNumber = true |
This file contains 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
scala> import scala.language.experimental.macros | |
import scala.language.experimental.macros | |
scala> def unimplicitlyImpl[A: c.TypeTag](c: reflect.makro.Context) = { | |
| val A = implicitly[c.TypeTag[A]].tpe | |
| val i = c.inferImplicitValue(A, silent = true) | |
| if (i == c.mirror.EmptyTree) c.reify(()) | |
| else sys.error("unexpected implicit of type %s: %s".format(A, i)) | |
| } | |
unimplicitlyImpl: [A](c: scala.reflect.makro.Context)(implicit evidence$1: c.TypeTag[A])c.mirror.Expr[Unit] |
OlderNewer