Welcome

I do stuff with Scala @ SoundCloud
I state and prove theorems of constructivist logic (proof).
I also connect points in topological spaces (proof).
My email: (λx.folonexlambda-calcul.us)@

Latest - Typelevel hackery tricks in Scala

There’s a lot of talks about typelevel things in Scala. “Shapeless”:shapeless has gained huge amount of attention lately. There are a lot of cool typelevel tricks out there, coined by “Miles Sabin”:milessabin, the type astonaut. Some even say, he does not exist at the runtime. Anyway, I’d like to collect some of those tricks here, for future reference. I’m also doing this to get a better understanding of those tricks. h2. Table table{border:1px solid black}. _.Trick _.Short description   “Unboxed Tagged Types”:taggedtypes Something like Haskell’s “newtype”:newtype, but better.   “Dependent types”:deptypestaste Have types depend on values   “Unapply”:unapplyorigin Reduce needed type annotations by guiding scala’s type inference   “Ambiguous implicits”:ambigimplicitsml A way to guarantee that a polymorphic function will not return some specific type h2. Unboxed Tagged Types There’s already a great explanation, including the needed intuition, in “Eric Torreborre’s blog”:taggedtypes. This technique allows for having some typelevel guarantees on the values. Here’s a motivating example. Say, you want to create a function, which operates on positive doubles. Here’s how you could go about this:
<pre>def log(i: Double): Option[Double] = if(i > 0) scala.math.log(i) else None</pre>
It’s a totally ok way to do this, but imagine, you want several such functions, and you want to chain them afterwards. You might create something like
<pre>def positive(i: Double):...

Read More »