Skip to content

Instantly share code, notes, and snippets.

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)
@runarorama
runarorama / gist:8833819
Created February 5, 2014 21:44
FromResponseUnmarshaller[Any]
scala> import spray.httpx.unmarshalling._
import spray.httpx.unmarshalling._
scala> implicitly[FromResponseUnmarshaller[Any]]
res2: spray.httpx.unmarshalling.FromResponseUnmarshaller[Any] = <function1>
scala> :t List(Vector(1), List(2))
List[scala.collection.immutable.Seq[Int] with scala.collection.AbstractSeq[Int]{def companion: scala.collection.generic.GenericCompanion[scala.collection.immutable.Seq with scala.collection.AbstractSeq{def dropRight(n: Int): scala.collection.immutable.Seq[Any] with scala.collection.AbstractSeq[Any]; def takeRight(n: Int): scala.collection.immutable.Seq[Any] with scala.collection.AbstractSeq[Any]; def drop(n: Int): scala.collection.immutable.Seq[Any] with scala.collection.AbstractSeq[Any]; def take(n: Int): scala.collection.immutable.Seq[Any] with scala.collection.AbstractSeq[Any]; def slice(from: Int,until: Int): scala.collection.immutable.Seq[Any] with scala.collection.AbstractSeq[Any]}]; def dropRight(n: Int): scala.collection.immutable.Seq[Int] with scala.collection.AbstractSeq[Int]{def companion: scala.collection.generic.GenericCompanion[scala.collection.immutable.Seq with scala.collection.AbstractSeq]; def dropRight(n: Int): scala.collection.immutable.Seq[Int] with scal
Rúnar Bjarnason
object Trampolines {
def odd[A](as: List[A]): TailRec[Boolean] =
as match {
case Nil => Return(false)
case _ :: xs => Suspend(() => even(xs))
}
def even[A](as: List[A]) = as match {
case Nil => Return(true)
case _ :: xs => Suspend(() => odd(xs))
@runarorama
runarorama / gist:9422453
Last active August 29, 2015 13:57
Suggestion for the new representation of `IO` in Scalaz.
import scalaz._
import \/._
import Free._
import scalaz.syntax.monad._
import java.util.concurrent.atomic.AtomicReference
import java.util.concurrent.CountDownLatch
object Experiment {
sealed trait OI[A] {
def map[B](f: A => B): OI[B]
Stefnuyfirlýsing fyrir "Ekki einungis hlutbundna hugbúnaðargerð"
Við erum að uppgötva betri leiðir til hugbúnaðargerðar með því að framkvæma hana og hjálpa öðrum að framkvæma. Í gegnum þessa vinnu höfum við lært að meta:
Föll og tög umfram klasa
Hreinleika umfram hverflyndi
Samsetningu umfram erfðir
Föll af hærra stigi umfram stefjuhespun
Aleindir umfram gildisleysi
From a recent "Bad Astronomy" post:
"We know the Universe is expanding; everywhere we look, it appears that galaxies are rushing away from us. If we run the clock backwards, this means the Universe was smaller in the past, and at some point must have had (nearly) zero volume. This point in time is commonly referred to as the Big Bang, when the expansion of the Universe started. 13.82 billion years later, here we are."
This is pure rationalism from beginning to end. Rationalism is a philosophical approach that clings to deductive proof as the standard of knowledge. So you move from one thing to the next by syllogism, and there is no essential difference between a true premise and a false one. We look at galaxies and see that they are redshifted, redshift is caused by motion away from the observer therefore the galaxies are rushing away from us, therefore the universe is expanding, therefore it _must_ have had (nearly) zero volume at some point, therefore Big Bang. It all depends on several logical leaps of d
@runarorama
runarorama / gist:9770894
Created March 25, 2014 20:43
Data kinds in Haskell to implement an n-way Either
ghci> data OneOf :: [*] -> * where Zero :: a -> OneOf (a ': xs); Succ :: OneOf xs -> OneOf (a ': xs)
ghci> let foo = Zero 'a'
ghci> let bar = Succ (Zero 42)
ghci> let baz = Succ (Succ (Zero True))
ghci> :t [foo, bar, baz]
[foo, bar, baz]
:: [OneOf ((':) * Char ((':) * Integer ((':) * Bool xs)))]
scala> 0.toByte.toInt
res5: Int = 0
scala> 0.toByte.toInt.abs
<console>:8: error: implicit numeric widening
0.toByte.toInt.abs
^
scala> res5.abs
res7: Int = 0