Skip to content

Instantly share code, notes, and snippets.

View ctongfei's full-sized avatar
:octocat:

Tongfei Chen ctongfei

:octocat:
View GitHub Profile
@ctongfei
ctongfei / ImplicitSummoner.scala
Last active May 13, 2017 20:03
Implicit Evidence Summoning
import scala.language.experimental.macros
import scala.language.higherKinds
/**
* @author Tongfei Chen
*/
trait ImplicitSummoner1[Ev[_]] {
/**
* Retrieves the implicit algebraic structure implicitly defined in this scope.
* @param ev The implicit object to be retrieved
@ctongfei
ctongfei / Nest.scala
Last active August 11, 2017 00:06
Typeclass with operations for Array[Array[...[Array[T]]...]] (Abstraction over N-d array dimensionality)
/**
* Witnesses that type [[T]] is the [[N]]-dimensional nested array of type [[A]].
* @author Tongfei Chen
*/
@implicitNotFound("Cannot prove that ${T} is the ${N}-dimensional JVM array of ${A}.")
trait Nest[T, A, N <: Nat] {
def classTagA: ClassTag[A]
def classTagT: ClassTag[T]
def newArray(ns: Int*): T
def dim: Int