Skip to content

Instantly share code, notes, and snippets.

View jdegoes's full-sized avatar

John A. De Goes jdegoes

View GitHub Profile
@jdegoes
jdegoes / Equiv.scala
Created April 22, 2014 02:27
Definition of Equiv.
/**
* Defines an equivalence between types A and B.
*
* Let ~_A be an equivalence relation on A, and ~_B be an equivalence relation
* on B.
*
* Let [a] denote the equivalence class of a in A ({a' | a ~_A a'}), and [b]
* denote the equivalence class of b in B ({b' | b ~_B b'}).
*
* Let `f: {[a] | a in A} -> {[b] | b in B]`, 'g: {[b] | b in B} -> {[a] | a in A}'
@jdegoes
jdegoes / generic.scala
Created April 27, 2014 16:17
Generic encoding of data in Scala
// ####### If you use a more generic lens you can transform types along the way.
case class Lens[S, A](get: S => A, set: (S, A) => S)
case class Prism[S, A](get: S => Option[A], unget: A => S) extends (A => S) {
def apply(a: A): S = unget(a)
def unapply(s: S): Option[A] = get(s)
}
// ####### Sum type
@jdegoes
jdegoes / errors-hk.txt
Created April 28, 2014 21:28
Lack of higher-kinded type inference???
[error] /Users/John/Documents/github/slamdata/slamengine/src/main/scala/slamdata/engine/physical/mongodb/planner.scala:468: type mismatch;
[error] found : slamdata.engine.analysis.fixplate.PhaseE[slamdata.engine.LogicalPlan2,slamdata.engine.PlannerError,Option[slamdata.engine.physical.mongodb.BsonField],Option[slamdata.engine.physical.mongodb.Selector]]
[error] (which expands to) slamdata.engine.analysis.fixplate.PhaseM[[X]scalaz.\/[slamdata.engine.PlannerError,X],slamdata.engine.LogicalPlan2,Option[slamdata.engine.physical.mongodb.BsonField],Option[slamdata.engine.physical.mongodb.Selector]]
[error] required: slamdata.engine.analysis.fixplate.PhaseM[EitherE,slamdata.engine.LogicalPlan2,Option[slamdata.engine.physical.mongodb.BsonField],?]
[error] val AllPhases = (FieldPhase[Unit]).fork(SelectorPhase, ExprPhase) >>> PipelinePhase
@jdegoes
jdegoes / scala-type-error.scala
Created May 7, 2014 22:13
Scala error message
[error] found : (slamdata.engine.analysis.fixplate.Term[[b]slamdata.engine.analysis.fixplate.Ann[slamdata.engine.LogicalPlan,A(in method apply)(in method apply)(in method apply)(in method apply)(in method apply)(in method apply)(in method apply)(in method apply),b]], slamdata.engine.analysis.fixplate.Term[[b]slamdata.engine.analysis.fixplate.Ann[slamdata.engine.LogicalPlan,A(in method apply)(in method apply)(in method apply)(in method apply)(in method apply)(in method apply)(in method apply)(in method apply),b]], slamdata.engine.LogicalPlan.JoinType, slamdata.engine.LogicalPlan.JoinRel, slamdata.engine.analysis.fixplate.Term[[b]slamdata.engine.analysis.fixplate.Ann[slamdata.engine.LogicalPlan,A(in method apply)(in method apply)(in method apply)(in method apply)(in method apply)(in method apply)(in method apply)(in method apply),b]], slamdata.engine.analysis.fixplate.Term[[b]slamdata.engine.analysis.fixplate.Ann[slamdata.engine.LogicalPlan,A(in method apply)(in method apply)(in method apply)(in method app
@jdegoes
jdegoes / scan.scala
Last active August 29, 2015 14:01
scalaz-stream scan
def scan[F[_], A, B](b: B, p: Process[F, A])(f: (B, A) => B): Process[F, B] = {
import Process._
def scan0(b: B, p: Process[F, A]) = scan(b, p)(f)
p match {
case h @ Halt(e) => h
case await : Await[F, Any, A] =>
Process.await[F, Any, B](await.req)(
@jdegoes
jdegoes / orelse.scala
Created June 4, 2014 20:01
Or else operator for Scalaz
implicit class AnyOps[A](value: A) {
def ?: [B](left: Option[B]): A \/ B = left.map(\/-(_)).getOrElse(-\/(value))
}
@jdegoes
jdegoes / cogroup.scala
Last active August 29, 2015 14:04
Simple, generic co-grouping with Scalaz
import scalaz._
import Scalaz._
object cogroup {
import \&/._
sealed trait Instr[A] {
def emit: List[A]
}
case class ConsumeLeft [A](emit: List[A]) extends Instr[A]
@jdegoes
jdegoes / die-data-types.purs
Last active August 29, 2015 14:07
Death to data types
module Main where
import Debug.Trace
import Prelude (flip, const, id, ($), (+), (<<<), show)
type Tuple a b = forall z. (a -> b -> z) -> z
mkTuple :: forall a b. a -> b -> Tuple a b
mkTuple a b = \f -> f a b
@jdegoes
jdegoes / bools.purs
Created October 27, 2014 18:53
Lunchtime experiment with booleans
-- booleans as a partition on a set
type Bool a = a -> Either a a
true' :: forall a. Bool a
true' = Right
false' :: forall a. Bool a
false' = Left
not' :: forall a. Bool a -> Bool a
@jdegoes
jdegoes / FileSystem.purs
Last active August 29, 2015 14:09
Figuring out the new guard layout rule
reify :: forall eff. ComponentClass (FileSystemTreeProps eff) FileSystemTreeState
reify = createClass spec
{ displayName = "FileSystemTree"
, getInitialState = \_ -> pure {collapsed: true}
, render = \this -> case this.props.files of
(FileType {"type" = "file", name = n}) -> pure $ D.div {}
[D.span {}
[ dataFileIcon
, D.rawText n
]