Skip to content

Instantly share code, notes, and snippets.


Block or report user

Report or block odersky

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile

Principled Meta Programming for Scala

This note outlines a principled way to meta-programming in Scala. It tries to combine the best ideas from LMS and Scala macros in a minimalistic design.

  • LMS: Types matter. Inputs, outputs and transformations should all be statically typed.

  • Macros: Quotations are ultimately more easy to deal with than implicit-based type-lifting

  • LMS: Some of the most interesting and powerful applications of meta-programming

View gist:040b88501bac8cfd6cbbd856b0836ae3
object Phantom {
type Nothing <: Any
type Any
def assume[T <: Any]: T
class Function1[-T <: Any, +R <: Any] {
def apply(x: T): R
odersky / A simpler way to returning the "current" type in Scala.
Last active Dec 15, 2018
A simpler way to returning the "current" type in Scala.
View A simpler way to returning the "current" type in Scala.
/** This is in reference to @tploecat's blog
* where he compares F-bounded polymorphism and type classes for implementing "MyType".
* Curiously, the in my mind obvious solution is missing: Use abstract types.
* A lot of this material, including an argument against F-bounded for the use-case
* is discussed in:
* Kim B. Bruce, Martin Odersky, Philip Wadler:
* A Statically Safe Alternative to Virtual Types. ECOOP 1998: 523-549
View FoldingViews.scala
package scalax.collection
import scala.collection.mutable.ListBuffer
/** FoldTransformers and the views based on them are a Scala
* adaptation, and to some degree an extension, of Rich Hickey's
* transducers for Clojure. They show that the concepts can be
* implemented in a type-safe way, and that the implementation is
* quite beautiful.
object FoldingViews {
odersky / equality.scala
Last active Oct 6, 2018
Better equality for Scala
View equality.scala
import annotation.unchecked.uncheckedVariance
/** The trait of things that can be compared safely */
trait Equals[-T] {
/** A witness of Equals' type parameter. Should only used for
* the constraint in EqlDecorator, hence, @uncheckedVariance should not be a problem.
type EqualsDomain = T @uncheckedVariance
You can’t perform that action at this time.