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
### from <http://lab.madscience.nl/oo.sh.txt> | |
#!/bin/bash | |
# --------------------------------------------------------------------------- | |
# OO support functions | |
# Kludged by Pim van Riezen <[email protected]> | |
# --------------------------------------------------------------------------- | |
DEFCLASS="" | |
CLASS="" |
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
// Context: https://github.com/larsrh/scalaz/tree/scalaz-seven/typelevel/src/main/scala/scalaz/typelevel | |
package scalaz | |
package typelevel | |
object HStream { | |
def fromForall[T[_]](elems: Forall[T]): HStream[T] = new HStream[T] { | |
def apply[N <: Nat](n: N) = elems[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
// Context <https://gist.github.com/2346456> | |
val hlist = 1 :: "foo" :: 3.0f :: HNil | |
val nones = HStream.const(None) | |
val wrapSome = new (Id ~> Some) { def apply[T](t: T) = Some(t) } | |
val somelist = hlist.transform(wrapSome) | |
val stream = somelist +: nones |
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
// Situation now | |
object UnionTypes { | |
type ![A] = A => Nothing | |
type !![A] = ![![A]] | |
trait Disj { self => | |
type D | |
type t[S] = Disj { |
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
trait AEither[L <: TList] { | |
// an `HList` where all elements are functions producing `R` | |
type Fold[R] = L#ToKList[({ type λ[α] = α => R })#λ]#Down | |
def fold[R](list: Fold[R]): R | |
} | |
case class AEitherCons[H, T <: TList](either: Either[H, AEither[T]]) extends AEither[TCons[H, T]] { |
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 language.experimental.macros | |
import scala.reflect.makro.Context | |
object Name { | |
def nameplicitly[T](implicit t0: T): Name[T] = macro nameplicitly_impl[T] | |
def nameplicitly_impl[T : c.TypeTag](c: Context)(t0: c.Expr[T]): c.Expr[Name[T]] = | |
c.reify(new Name[T] { def t = t0.splice }) |
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
object KleisliValidation extends App { | |
import scalaz._ | |
import Scalaz._ | |
import scala.util.control.Exception._ | |
type EEither[+T] = Either[String, T] | |
def toDouble(s: String): EEither[Double] = allCatch.either(s.toDouble).fold(_.toString.left, _.right) | |
def sqrt(d: Double): EEither[Double] = if (d >= 0) math.sqrt(d).right else "sqrt(%s) is too complex for me".format(d).left | |
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
// <http://stackoverflow.com/q/12204869> | |
def map[T, U, X, CC[X] <: Traversable[X]](cct: CC[T], f: T => U)(implicit cbf: CanBuildFrom[CC[T], U, CC[U]]): CC[U] = | |
cct.map(t => f(t))(collection.breakOut(cbf)) | |
/* | |
scala> map(List(1,2,3), (x: Int) => x.toString) | |
res1: List[java.lang.String] = List(1, 2, 3) | |
*/ |
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 java.net.URI | |
import scalaz.concurrent.Promise | |
import scalaz._ | |
import Scalaz._ | |
import language.implicitConversions | |
case class Cert(cn: String, pubKey: BigInt, webids: List[URI] ) | |
trait RequestHeader { |
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
sealed trait GenericList[+M[_]] { | |
final def :^:[A, N[X] >: M[X]](elem: N[A]): GenericCons[N, A, this.type] = | |
GenericCons[N, A, this.type](elem, this) | |
} | |
case class GenericCons[M[_], H, +T <: GenericList[M]]( | |
head: M[H], | |
tail: T |
OlderNewer