Skip to content

Instantly share code, notes, and snippets.

View markhibberd's full-sized avatar

markhibberd markhibberd

View GitHub Profile
user=> (defn adder [x y] (+ x y))
(defn adder [x y] (+ x y))
#'user/adder
user=> (partial adder)
(partial adder)
#<user$adder user$adder@2c40072a>
user=> (def adderx (partial adder))
(def adderx (partial adder))
#'user/adderx
user=> (adderx 1)
@markhibberd
markhibberd / example.clj
Last active August 29, 2015 13:56
lens in clojure
;; repl session
(use 'lens)
(defrecord Address [street city postcode])
(defrecord Person [name age address])
(defrecord User [uid username identity password])
(def -postcode (mklens :postcode))
(def -city (mklens :city))
@markhibberd
markhibberd / Example.scala
Created February 27, 2014 18:26
An example of manually encoding and decoding.
import argonaut._, Argonaut._
class Example(val s: String, val i: Int)
object Example {
implicit def ExampleEncodeJson: EncodeJson[Example] =
EncodeJson(example => Json(
"s" := example.s,
"i" := example.i))
scalacOptions ++= Seq("-deprecation", "-unchecked", "-optimise", "-Yinline-warnings", "-feature", "-language:implicitConversions", "-language:higherKinds", "-language:postfixOps")
Host B
ProxyCommand ssh A nc -w 360 B 22
Host C
ProxyCommand ssh B nc -w 360 C 22
sealed trait Accent[A]
final case class Zed(n: Int) extends Accent[Int]
final case class Zee(s: String) extends Accent[String]
object Example {
def twice[A](accent: Accent[A]): Accent[A] = accent match {
case Zed(n) => Zed(n + n)
case Zee(s) => Zee(s + s)
}

Category:

Combo: Talk & Workshop

Target:

Intermediate - Expected knowledge of basic Scala or Haskell syntax
               (examples will be contrasted in both).

Language:

@markhibberd
markhibberd / ListT.scala
Created April 12, 2014 10:01
ListT / NondetT - a sensible ListT layered with a cut operation.
import scalaz._, Scalaz._
case class ListT[F[+_], +A](stepListT: F[TStep[A, ListT[F, A]]]) {
def ++[AA >: A](other: ListT[F, AA])(implicit F: Monad[F]): ListT[F, AA] = ListT(for {
s <- stepListT
r <- s match {
case TNil() =>
other.stepListT
case TCons(a, x) =>
TStep.cons(a, x ++ other).pure[F]
@markhibberd
markhibberd / Aaa-notes.md
Last active August 29, 2015 13:59
lots of questions

So what I understand to be your questions:

  1. What is a coherency problem?
  2. What does over constained code look like / cause?
  3. How do you lose your "desired" instance?

A way to step through understanding this problem:

  • Oh shit, If I have local type classes, I have to handle crazy wacky cases in my implementation, this will likely have performance and correctness implications (see Coherency.scala)
  • What happens if I close over constraint on construction? Oops if I close over it, I end up with OverConstrained code (see OverConstrainedCode.scala) and worse I still have coherency issues, and the ability to lose my intended behavious (LosingAnInstance.scala)
  • Oh wow, if I just don't do local type classes, by never define conflicting implicits, and ascribe a single type to each behaviour, everything is simple and just works.

This is a basically what we are running into on https://github.com/argonaut-io/argonaut/tree/series/6.0.x:

[23:22] [        seanparsons  ] With a fresh sbt I get this from 2.9.3: [success] Total time: 78 s, completed 21-Apr-2014 14:20:53
[23:25] [        seanparsons  ] With a fresh sbt I get this from 2.10.4: [success] Total time: 60 s, completed 21-Apr-2014 14:22:57
[23:25] [        seanparsons  ] But in the cross build that second one was: [success] Total time: 332 s, completed 21-Apr-2014 14:01:57

And it seems to be exponential. We are building for 4 platforms (2.9.2, 2.9.3, 2.10.4, 2.11.0). Running ./sbt "; clean ; +test" can take hours.