The article previously hosted here is now published on my website: My ErgoDox Keyboard.
class A | |
class A2 extends A | |
class B | |
trait M[X] | |
// | |
// Upper Type Bound | |
// | |
def upperTypeBound[AA <: A](x: AA): A = x |
/** GADTs in Scala and their limitations */ | |
/** Background: what is an algebraic data type (ADT) ? | |
* ADT: (possibly) recursive datatype with sums and products | |
* In scala - a trait with case classes (case class is product, subtyping is sum) | |
*/ | |
/** Motivation: untyped embedded DSL doesn't prevent nonsensical expressions */ | |
sealed trait Expr { | |
def apply(other: Expr) = Ap(this, other) |
import java.io.IOException; | |
import java.net.URL; | |
import java.util.Date; | |
import java.util.List; | |
import java.util.logging.Level; | |
import org.json.*; | |
import org.openqa.selenium.*; | |
import org.openqa.selenium.chrome.*; | |
import org.openqa.selenium.logging.*; |
/** Domain mapped XML doesnt have to be a boilerplate filled annotational mess. Using shapeless automatic | |
* typeclass derivation and a little scalaz magic, it becomes painless. Requires shapeless-2.1.0 and scala >2.10 | |
* | |
* | |
* import scalaz._ | |
* import scalaz.std._ | |
* import anyVal._ | |
* import list._ | |
* import scala.xml._ | |
* |
object Demo { | |
// A couple of type classes with type members ... | |
trait Foo[T] { | |
type A | |
} | |
object Foo { | |
implicit val fooIS = new Foo[Int] { type A = String } | |
} |
Every application ever written can be viewed as some sort of transformation on data. Data can come from different sources, such as a network or a file or user input or the Large Hadron Collider. It can come from many sources all at once to be merged and aggregated in interesting ways, and it can be produced into many different output sinks, such as a network or files or graphical user interfaces. You might produce your output all at once, as a big data dump at the end of the world (right before your program shuts down), or you might produce it more incrementally. Every application fits into this model.
The scalaz-stream project is an attempt to make it easy to construct, test and scale programs that fit within this model (which is to say, everything). It does this by providing an abstraction around a "stream" of data, which is really just this notion of some number of data being sequentially pulled out of some unspecified data source. On top of this abstraction, sca
object Nullable { | |
sealed trait NullableTag | |
type Nullable[A] = A with NullableTag | |
def nullAs[B]: Nullable[B] = | |
null.asInstanceOf[Nullable[B]] | |
implicit class ToNullable[A](val a: A) extends AnyVal { | |
def `?`: Nullable[A] = a.asInstanceOf[Nullable[A]] | |
} |
import shapeless._ | |
object CaseClassMergeDemo extends App { | |
import mergeSyntax._ | |
case class Foo(i: Int, s: String, b: Boolean) | |
case class Bar(b: Boolean, s: String) | |
val foo = Foo(23, "foo", true) | |
val bar = Bar(false, "bar") |