Skip to content

Instantly share code, notes, and snippets.

@runarorama
runarorama / Perfect
Created March 11, 2012 15:52
Perfect binary trees
object Perfect {
sealed trait Perfect[+A] {
// TODO: Try to implement flatMap.
// Hint: It can't be done. Why?
}
case class Empty extends Perfect[Nothing]
case class Node[+A](head: A, tail: Perfect[Perfect[A]]) extends Perfect[A]
sealed trait Square[+A]
@runarorama
runarorama / gist:2030578
Created March 13, 2012 18:40 — forked from mergeconflict/pimps.scala
typeclass fu
// reifies the assertion that type A is an instance of typeclass F
final class instance[A, F[_]](value: A, typeclass: F[A]) {
def apply[B](f: (F[A], A) => B): B = f(typeclass, value)
}
// provides an implicit conversion from any A to the above "instance" wrapper
object instance {
implicit def anyToInstance[A, F[_]](a: A)(implicit fa: F[A]) = new instance(a, fa)
}
@runarorama
runarorama / gist:3699765
Created September 11, 2012 16:47
Extremely helpful error message
[error] /Users/runar/work/Reporting/src/main/scala/com/clarifi/reporting/relational/Rel.scala:191: ambiguous implicit values:
[error] both object TableNameOrder in package reporting of type object com.clarifi.reporting.package.TableNameOrder
[error] and object TableNameOrder in package reporting of type object com.clarifi.reporting.package.TableNameOrder
trait True
trait False
def impl(c: Context)(nExpr: c.Expr[Int]): c.Tree = {
import c.universe._
val n: Int = c.eval(c.Expr[Int](c.resetAllAttrs(nExpr.tree)))
if (n >= 3) tq"True" else tq"False"
}
type AtLeastThree(i: Int) = macro impl
@runarorama
runarorama / Scalaz Google Code page
Created April 22, 2013 16:31
Scalaz Google Code page
<b>The source for Scalaz is now hosted on !GitHub - http://github.com/scalaz/scalaz</b>
Scalaz is a library written in the [http://scala-lang.org/ Scala Programming Language]. The intention of Scalaz is to include general functions that are not currently available in the core Scala API. The scalaz-core module depends only on [http://www.scala-lang.org/docu/files/api/index.html the core Scala API] and the core Java 2 Standard Edition API. Scalaz is released under a BSD open source licence making it compatible with the licence of the Scala project.
[http://code.google.com/p/scalaz/wiki/Scalaz6 Scalaz 6.0.4] was released in January 2012, targeting Scala 2.8.1, 2.9.0.1, 2.9.1 and 2.10.0-M1. [http://scala-tools.org/repo-releases/org/scalaz/scalaz-full_2.9.1/6.0.4/scalaz-full_2.9.1-6.0.4.jar Full download for 2.9.1]
[Scalaz7 Scalaz 7] is currently being developed. This is a rewrite to address the challenges posed by type class inheritance. The first release of this series is expected in April 2012.
== Community
<html>
<head></head>
<body>
<script type="text/javascript" src="//ajax.googleapis.com/ajax/static/modules/gviz/1.0/chart.js"> {"dataSourceUrl":"//docs.google.com/spreadsheet/tq?key=0AqPvyu_QqshwdHdtOFFZeThtSTZaLVExTlIweUYxaFE&transpose=0&headers=1&range=H1%3AJ100&gid=0&pub=1","options":{"titleTextStyle":{"bold":true,"color":"#000","fontSize":16},"vAxes":[{"titleTextStyle":{"color":"#222","italic":true,"fontSize":"7"},"useFormatFromData":true,"minValue":null,"viewWindow":{"min":null,"max":null},"maxValue":null},{"useFormatFromData":true,"minValue":null,"viewWindow":{"min":null,"max":null},"maxValue":null}],"bubble":{"opacity":"0.4","textStyle":{"fontSize":"7"}},"title":"Chart title","booleanRole":"certainty","height":609,"animation":{"duration":0},"legend":"right","colors":["#3366CC","#DC3912","#FF9900","#109618","#990099","#0099C6","#DD4477","#66AA00","#B82E2E","#316395","#994499","#22AA99","#AAAA11","#6633CC","#E67300","#8B0707","#651067","#329262","#5574A6","#3B3EAC","#B77322","#16D620","#B91383","#F4359E",
Take my hand, let's look back, release the tether
from the dark nightmare that ghosts rock and roll.
Longer, lower, they want to starve the day.
Enormous, tiny thing. There is often glory in the silence.
In the middle of a dream that grasps with hot hands--
longer, higher, it raises the new day.
Feel, how the mind pulls ahead of itself [/gets out of its bed]
and feel everything that will be, that was, and that is,
@runarorama
runarorama / gist:6956002
Last active December 25, 2015 09:39
Three theories of value

Subjectivist theory: The subjectivist theory holds that the good resides in consciousness, independent of reality. If the wish or feeling of value exists in the mind, then that constitutes value. Specific versions differ on whose mind is involved. It could be God's, society's (i.e. other people's), or one's own. Both "it is a value because God says so" and "it is a value because my feelings say so" are instances of this theory. The subjectivist theory holds that the value bears no relation to the facts of reality, that it is the product of consciousness, created by feelings, desires, intuitions, or whims. The irreducible primary in this theory is: desire.

Intrincisist theory: The intrinsicist theory holds that the good resides in reality, independent of consciousness. That is "the good" is good in, by, and of itself, regardless of its relationship with anyone or anything else. "Gold is inherently valuable", and "always indent five spaces", and "we must always serve our country", are instances of this theor

The Magic of Adequate Surprise
There was brouhaha and a big crowd on Friday when the first of three showings of a new opera by Gunnar Þórðarson sounded over a fully packed church at Skálholt. The ostensible occasion was, in accord with our time's inclination for events, the 350th anniversary of the death of the bishop's daugther Ragnheiður, upon which also was sung for the first time the Icelanders' most traditional funeral psalm, "Allt eins og blómstrið eina" [Just like the lone blossom]; the same year that her father brought the most important manuscript of Norse antiquity, the Codex Regius of the Prose Edda, as a gift to Frederick III of Denmark. It is therefore safe to say that the framework of time and place was appropriate. But of course a new Icelandic opera in full length was no less of an occasion, since such a thing does not happen every year. Certainly many people's curiosity was piqued that here was an original work by a self-taught songwriter. It's one thing to be able to endlessly write evergre
scala> res8
res9: Option[Int] =
Some(HttpResponse(200 OK))
scala> res9.get
java.lang.ClassCastException: spray.http.HttpResponse cannot be cast to Int
at .<init>(<console>:33)