Archive for February, 2009

Dear Agile/Lean/Scrum/XP Person

Thursday, February 19th, 2009

I want you to imagine a scenario for me.

Did you know that carrying a Tiger’s Eye crystal provides protection and clearer thought? Yeah OK I agree, all that crystal healing stuff is just silly nonsense that essentially exists to provide a placebo effect. This doesn’t stop some people from genuinely believing in the healing properties of crystals of course — and they are certainly being exposed to a bias of confirmation. This is because a critical failure of rational faculties has occurred somehow — you and I see straight through it; it’s obviously nonsense! But they seek peer reinforcement for their mistake and have a hard time understanding what it is like to not believe in the healing properties of crystals.

If it is so blatantly false, then why do some apparently intellectually-equipped people swear by it?

Now suppose you were invited to be healed by a crystal healer and you decline because you have other relevant tasks to achieve. What would you say when asked why the declination? You wouldn’t want to insult the questioner — that they believe such a ridiculous proposition doesn’t compel you to simply insult their person, however, if you were to answer the question honestly, they would take offence. You’re caught in a pickle now, so what then? Dishonesty? Appeasing their fantasy?

Would you answer with a question, “I don’t believe crystal healing is effective, because there is no empirical data to suggest it is so. Can you show me otherwise?” to which they respond, “Sure! We use a process of high energy physics photography to derive our scientific conclusions.” So what now? They just provide more bunk — again, you and I see straight through it. You can make no progress. The only reasonable conversation you can have is one about how to deduce true facts in general.

But it gets worse, now imagine that the invitation to the crystal healing session requires that you drink frog poison upon entry, because the ancient Egyptians did it to appease the Gods with a small personal sacrifice. In this scenario, 150 people die each year from ingestion of frog poison, but the crystal healers put this down to anger from the Gods that must only be appeased further, otherwise it will be 300!

At this point, you now object to attendance on the grounds that it is detrimental to your health. Furthermore, you may even feel a moral obligation toward anybody else who has been coaxed into this form of abuse. You’re in a really big pickle now aren’t you?

This is exactly the pickle I am in when you try to peddle your pseudoscience onto me. I don’t want to insult you, but I don’t want to suffer the adverse effects of your crack-pottery. Furthermore, I don’t want other people, who have been tricked (as you have been), to suffer — I feel compelled to warn them against it. Again, not to offend you (though it might), but because I have a deep sense of empathy for all people, including you.

On the other hand, I could do what a lot of us non-crystal-healers do and be proactive in completely ignoring your existence wherever possible but that doesn’t take away from my sense of empathy.

IntelliJ IDEA leaps ahead for Scala development

Tuesday, February 17th, 2009

Much of my work is in Scala or Haskell. Lately, it is mostly in Scala. Sometimes I have the unfortunate imposition to use Java by a false authority. This is where Functional Java is handy — in an attempt to make Java somewhat practical, even if only to a small degree.

JetBrains has granted Functional Java an open source licence to use their IntelliJ IDEA. I recently downloaded the 8.1 version and started working on some of the Scala components of Functional Java.

It is pleasing to have a usable IDE that is easy to install on my 64-bit Linux machine. It is more pleasing that the Scala plugin has all the required fundamental features and few bugs. I also use a 32-bit machine running Linux and it was just as much a breeze to install and use there. Of course, I do not use Compiz on these machines, since it screws up swing applications. I do, however, use xmonad window manager, which boosts productivity quite a lot.

The Scala plugin has the much desired “Go to declaration”, is able to report many compile-time errors — though not all and I expect I push Scala a bit harder than many others in terms of finding quirks in the language. It has many other features — some of which need a bit of work, but many of which are significantly ahead of other IDEs, particularly when it comes to stability.

Thanks JetBrains for making it viable to use advanced programming concepts in a capable programming language.

Funky Scala Bifunctor

Saturday, February 14th, 2009

A co-variant binary functor (aka bifunctor) is any type constructor with a kind * -> * -> * that can satisfy identity and composition when mapping on either type variable. A couple of examples of bifunctors in the Scala library are

  • Tuple2
  • Either

Note that Function1 is not a bifunctor, evident by the fact that it is contra-variant in its first type variable. It is notable that Tuple2 represents conjunction while Either represents the disjunction of two theorems under the Curry-Howard Isomorphism (Function1 represents implication).

A bifunctor often combines the two possible mappings into a function called bimap with the signature (Scala-ish syntax):

F[A, B] => (A => C) => (B => D) => F[C, D]

Recall that identity and composition laws must satisfy in the implementation.

Consider now an implementation of bimap for both Tuple2 and Either:

trait Bifunctor[F[+_, +_]] {
  def bimap[A, B, C, D](fa: F[A, B], f: A => C, g: B => D): F[C, D]
}
 
object Bifunctor {
  implicit def Tuple2Bifunctor = new Bifunctor[Tuple2] {
    def bimap[A, B, C, D](fa: (A, B), f: A => C, g: B => D) = 
      (f(fa._1), g(fa._2))
  }
 
  implicit def EitherBifunctor = new Bifunctor[Either] {
    def bimap[A, B, C, D](fa: Either[A, B], f: A => C, g: B => D) = 
      fa match {
        case Left(a) => Left(f(a))
        case Right(b) => Right(g(b))
      }
  }
}

These implementations are quite easy to understand, but they are not so pretty to use. This is an unfortunate consequence of a number of factors about Scala, including:

  • Higher-kinds are never inferred
  • Functions cannot be used in infix position

In Scala, methods that end with a colon (:) can have their arguments swapped when not using dot notation. For example, the following two lines are equivalent:

obj.::(arg) 
arg :: obj

This is evident when using scala.List and the cons (::) method.

We might wrap up our Bifunctor implementation similarly and create some nice syntax for mapping on the bifunctor. For example, let us define three methods on any Bifunctor value:

  • <-: for mapping on one side
  • :-> for mapping on the other side
  • <-:-> for mapping on both sides
trait BifunctorW[F[+_, +_], A, B] {
  val value: F[A, B]
  val bifunctor: Bifunctor[F]
 
  def <-:->[C, D](f: A => C, g: B => D) = bifunctor.bimap(value, f, g)
 
  def <-:[C](f: A => C) = bifunctor.bimap(value, f, identity[B])
 
  def :->[D](g: B => D) = bifunctor.bimap(value, identity[A], g)
}
 
object BifunctorW {
  // a somewhat verbose but handy trick
  // for partially applying type variables.
  def bifunctor[F[+_, +_]] = new BifunctorApply[F] {
    def apply[A, B](v: F[A, B])(implicit b: Bifunctor[F]) = 
        new BifunctorW[F, A, B] {
      val value = v
      val bifunctor = b
    }
  }
 
  trait BifunctorApply[F[+_, +_]] {
    def apply[A, B](v: F[A, B])(implicit b: Bifunctor[F]): BifunctorW[F, A, B]
  }
 
  implicit def Tuple2Bifunctor[A, B](v: (A, B)) = 
    bifunctor[Tuple2](v)
 
  implicit def Either2Bifunctor[A, B](v: Either[A, B]) = 
    bifunctor[Either](v)
}

So we’ve wrapped a value and its Bifunctor implementation. So how does it look when we use it? Like this!

object Main {
  def main(args: Array[String]) {
    import BifunctorW._
 
    val x: Either[Int, String] = Left(7)
    val y = ("hello", 42)
 
    val f = (n: Int) => n + 1
    val g = (s: String) => s.reverse
    val h = (s: String) => s.toUpperCase
    val i = (n: Int) => n * 2
 
   // Pretty neat eh?
    val p = f <-: x :-> g
    val q = h <-: y :-> i
 
    // $ scala Main
    // Left(8)
    // (HELLO,84)
    println(p)
    println(q)
  }
}

And I think that’s an elegant use of a sometimes baroque (when trying for advanced concepts) language :)

Third World Medicine

Saturday, February 14th, 2009

I’ve had two operations on my right ankle and both have failed to correctly diagnose and address the underlying symptomatic complaints that have existed for over 18 months. I am now aware of what the correct diagnosis is, verifiable with historical and radiographic evidence and repeatable symptomatic observations.

The surgeons are cautious given that I’ve already used up two of my available surgery cookie quota and hesitant to go again. This is despite having an exact pinpoint of where the problem is and published literature of what procedure is required. I simply have no rational explanation for this and, if it weren’t for my discomfort, it would leave me in awe.

The diagnosis is anteromedial osseous impingement of the right ankle visible on CT, verified by a radiologist and repeatable on dorsiflexion. This has come about from repeated trauma and in particular, a grade 3 inversion sprain in July 2007. I require a resection of this excess ossification.

I am asking (begging) my international audience for recommendations of a surgeon who is willing to perform this procedure as soon as possible in any part of the world. I suspect, only because I have no other explanation, that there is some bureaucratic restriction preventing me from making progress with surgeons here.

Suggestions please?