Skip to content

Instantly share code, notes, and snippets.

import scala.language.higherKinds
import scala.language.implicitConversions
trait Forall[M[_]] {
def apply[A]: M[A]
}
trait Maybe[A] extends Forall[({ type F[R] = (A => R, => R) => R })#F]
object Maybe {
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)
@xuwei-k
xuwei-k / Prob44_2.scala
Last active December 18, 2015 13:39 — forked from ponkotuy/Prob44_2.d
object Prob44_2 {
def pentagonal(n: Int) = n*(3*n - 1)/2
private[this] val pentagonals = Iterator.from(0).map(pentagonal).takeWhile(_ < (Int.MaxValue >> 2)).toArray
def isPenta(n: Int) = {
val dbl = (1.0 + math.sqrt(1 + 24*n))/6.0
val int = dbl.toInt
pentagonal(int) == n || pentagonal(int + 1) == n
}
@xuwei-k
xuwei-k / -Xprint:jvm
Last active December 26, 2015 16:48 — forked from okapies/gist:7182102
[[syntax trees at end of jvm]] // Param.scala
package <empty> {
final class Param extends Object {
<paramaccessor> private[this] val i: Int = _;
<stable> <accessor> <paramaccessor> def i(): Int = Param.this.i;
override <synthetic> def hashCode(): Int = Param.hashCode$extension(Param.this.i());
override <synthetic> def equals(x$1: Object): Boolean = Param.equals$extension(Param.this.i(), x$1);
def <init>(i: Int): Param = {
Param.this.i = i;
Param.super.<init>();
@xuwei-k
xuwei-k / functor.scala
Last active December 28, 2015 20:38 — forked from gakuzzzz/functor.scala
trait Functor[A, F[_]] { self =>
def fmap[B](f: A => B): F[B]
}
trait ~>[-F[_], +G[_]]{
def apply[A](fa: F[A]): G[A]
}
object Functor {
@xuwei-k
xuwei-k / ints.scala
Created January 15, 2014 18:50 — forked from non/ints.scala
package quantity
// like Nat, but for integers
trait Z
// Pos means positive-or-zero, and Neg means negative-or-zero
trait Pos extends Z { type P <: Pos }
trait Neg extends Z { type N <: Neg }
class Zero extends Pos with Neg { type N = Zero }
import scalaz._
import \/._
import Free._
import scalaz.syntax.monad._
object Experiment {
sealed trait OI[A] {
def map[B](f: A => B): OI[B]
}
case class Async[A](k: (A => Trampoline[Unit]) => Unit) extends OI[A] {
case class B()
trait A {
implicit val b = B()
}
object App extends A {
def main(args: Array[String]): Unit = {
printImplicit
}
@xuwei-k
xuwei-k / build.sbt
Last active October 26, 2016 05:39 — forked from runarorama/gist:a8fab38e473fafa0921d
Coproduct Example
scalaVersion := "2.11.1"
libraryDependencies ++= Seq(
"org.scalaz" %% "scalaz-core" % "7.1.0-M7"
)
scalacOptions ++= Seq("-deprecation", "-language:_")

As compiled by Kevin Wright a.k.a @thecoda

(executive producer of the movie, and I didn't even know it... clever huh?)

please, please, please - If you know of any slides/code/whatever not on here, then ping me on twitter or comment this Gist!

This gist will be updated as and when I find new information. So it's probably best not to fork it, or you'll miss the updates!

Monday June 16th