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)@`

There’s a lot of talks about typelevel things in Scala. Shapeless has gained huge amount of attention lately. There are a lot of cool typelevel tricks out there, coined by Miles Sabin, 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.

Trick | Short description |
---|---|

Unboxed Tagged Types | Something like Haskell’s newtype, but better. |

Dependent types | Have types depend on values |

Unapply | Reduce needed type annotations by guiding scala’s type inference |

Ambiguous implicits | A way to guarantee that a polymorphic function will not return some specific type |

There’s already a great explanation, including the needed intuition, in Eric Torreborre’s blog. 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:

`def log(i: Double): Option[Double] = if(i > 0) scala.math.log(i) else None`

It’s a totally ok way to do this, but imagine, you want several such functions, and you want to...

- Typelevel hackery tricks in Scala ( Mar 2013 )
- Uniqueness types in Scala ( Feb 2013 )
- What will programming look like in 2020 -- my personal wishlist ( Jan 2013 )
- Best of the 2012 ( Jan 2013 )
- Exercises on implementing Reader, Writer and State monads in Scala ( Oct 2012 )