Skip to content

Instantly share code, notes, and snippets.

View qingwei91's full-sized avatar

Qing qingwei91

View GitHub Profile
case class HFix[F[_[_], _], A](unfix: F[HFix[F, ?], A])
// does not compile
Fix(QueryPathF("key", Fix(QueryStringF))
case class Fix[F[_]](unfix: F[Fix[F]])
// compiles with `-Ypartial-unification` compiler flag
val expression = QueryPathF("oh", QueryPathF("my", QueryStringF))
sealed trait QueryF[+F[_], A]
case object QueryStringF extends QueryF[Nothing, String]
case object QueryBoolF extends QueryF[Nothing, Boolean]
case class QueryPathF[F[_], A](path: String, next: F[A]) extends QueryF[F, A]
def typeMatch[A, B](a: A, b: B)(implicit eq: A=:=B) = ()
val queryString = QueryPath("my", QueryString)
val queryNestedString = QueryPath("my", QueryPath("oh", QueryString))
typeMatch(queryString, queryNestedString) // compiles
// simplified
sealed trait Query[A]
case object QueryString extends Query[String]
case object QueryBool extends Query[Boolean]
case class QueryPath[A](path: String, next: Query[A]) extends Query[A]
// sample data
// {
// "oh": {
// "my": "zsh"
// }
@qingwei91
qingwei91 / TypedQuery.scala
Created February 10, 2019 16:42
Recursion Scheme for GADT examples
// Recursive GADT
sealed trait Query[A]
case object QueryString extends Query[String]
case object QueryBool extends Query[Boolean]
case class QueryPath[A](path: String, next: Query[A]) extends Query[A]
// sample data
// {

Motivation

Informally, kalman filter helps us to improve estimation of data when measurement is subject to noise. 3 basic concepts to understand

Measurement

Data collected, it is inaccurate due to noise and also lack of accuracy due to collection mechanism, ie. inaccurate sensor

typically denoted as Z

object CacheMacroImpl {
/**
*
* @param fnTypeParams - Type params of annotation instance, remember our cache macro is generic `class cache[K, V]`,
this will capture Seq(K, V)
* @param cacheExpr - Argument pass to `cache` macro, should be type of `CacheBackEnd[K, V]`
* @param annotatedDef - Methods that is annotated
*/
def expand(fnTypeParams: Seq[Type], cacheExpr: Term.Arg, annotatedDef: Defn.Def): Term = {