Skip to content

Instantly share code, notes, and snippets.

View ariwaranosai's full-sized avatar
🐒
hou

在原佐为 ariwaranosai

🐒
hou
  • HangZhou
View GitHub Profile
0x0cb4405A1c6d8e9344304a3353279bB301e9343a
import Bool._
import Equality._
sealed trait Bool {
type V <: Bool
type ACT[T <: Up, F <: Up, Up]
}
trait True extends Bool {
type V = True
/**
* Created by ariwaranosai on 2017/1/3.
*
*/
trait ExpAlg[T] {
def lit(n: Int): T
def add(x: T, y: T): T
}
@ariwaranosai
ariwaranosai / FTT.scala
Created January 5, 2017 14:04
Final tagless
trait ExpAlg[T] {
def lit(n: Int): T
def add(x: T, y: T): T
}
object ExpAlg {
implicit def toIntExpOps[T](n: Int)(implicit m: ExpAlg[T]): ToIntExpOps[T] =
new ToIntExpOps[T](n)(m)
abstract class Exp
case class Lit(n: Int) extends Exp
case class Neg(e: Exp) extends Exp
case class Add(e1: Exp, e2: Exp) extends Exp
object Exp {
implicit def toLit(n: Int): Lit = Lit(n)
def eval(e: Exp): Int = e match {
case Lit(n) => n
case Neg(e) => -eval(e)
@ariwaranosai
ariwaranosai / bangumi.py
Created September 17, 2016 08:17
for test
# coding=utf-8
__author__ = 'shiheng'
from functools import partial
class Bangumi(object):
u'''
Bangumi的一个查询
'''
def __init__(self, dic):
self.obj = dic
def __getattr__(self, item):
@ariwaranosai
ariwaranosai / ST.scala
Created August 28, 2016 14:14
State Monad and STRef
/**
* Created by ariwaranosai on 16/8/28.
*
*/
import ST._
case class World[S]()
case class ST[S, A](f: World[S] => (World[S], A)) {
import scalaz.{Monad}
import scalaz.OptionT
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
import scalaz.std.scalaFuture._
import scala.language.existentials
import scala.language.experimental.macros
import scala.language.higherKinds
object TypeLevel {
def main(args: Array[String]) {
import scala.language.higherKinds
sealed trait Bool {
type IF[T <: Up, F <: Up, Up]
}
sealed trait True extends Bool {
type IF[T <: Up, F <: Up, Up] = T
@ariwaranosai
ariwaranosai / view bound
Last active March 24, 2016 13:57
add <%< to scala great than 2.10
sealed abstract class <%<[-From, +To] extends (From => To) with Serializable
object <%< {
implicit def conformsOrViewsAs[A <% B, B]: A <%< B = new (A <%< B) {def apply(x: A) = x}
}