- 値のwrap/unwrapがない
- インスタンスの定義が単純
- インスタンスが一意に定まらない
コンパニオンオブジェクトの同一階層に複数のimplicit valueを定義した場合
- importが必須
- エラーがわかりづらい(could not find implicit value)
| extern crate regex; | |
| use regex::Regex; | |
| #[derive(Debug)] | |
| enum ParseResult<T> { | |
| Success { result: T, next: String }, | |
| Failure | |
| } | |
| impl<T> ParseResult<T> { |
| object GADTs { | |
| sealed trait Data1[A] | |
| case class Constructor1() extends Data1[Int] | |
| sealed trait Data2 { type T } | |
| case class Constructor2() extends Data2 { type T = Int } | |
| def f1[A](data: Data1[A]): A = data match { case Constructor1() => 0 } | |
| //def f2[A](data: Data2 { type T = A }): A = data match { case Constructor2() => 0 } |
| import scala.annotation.tailrec | |
| sealed abstract class Var { | |
| def walk(subst: Subst): Var = { | |
| @tailrec | |
| def go(v: Var, stack: List[Var], acc: Option[Var]): Var = | |
| v match { | |
| case Unbound(k) => | |
| subst.get(k) match { |
| import scala.annotation.tailrec | |
| sealed abstract class Queue[U <: Union, -A, +B] { | |
| def apply(a: A): Free[U, B] = { | |
| @tailrec | |
| def go(tpe: { type T })(arrows: Queue[U, tpe.T, B], value: tpe.T): Free[U, B] = | |
| arrows.view match { | |
| case One(f) => f(value) | |
| case cons@Cons() => |
| package kits.free | |
| import scala.annotation.tailrec | |
| sealed abstract class Queue[R[_], -A, +B] { | |
| def :+[C](f: B => Free[R, C]): Queue[R, A, C] = new Node(this, new Leaf(f)) | |
| def ++[C](that: Queue[R, B, C]): Queue[R, A, C] = new Node(this, that) |
| import scala.annotation.tailrec | |
| sealed abstract class Queue[F[_], A, B] { | |
| def :+[C](f: B => F[C]): Queue[F, A, C] = | |
| new Node(this, new Leaf(f)) | |
| def ++[C](that: Queue[F, B, C]): Queue[F, A, C] = | |
| new Node(this, that) |
| @tailrec | |
| def go[F[_], A, B](arg: (Queue[F, A, T], Queue[F, T, B]) forSome { type T }): View[F, A, B] = { | |
| arg match { | |
| case (Leaf(v), y) => new Cons(v, y) | |
| case (Node(l, r), y) => go[F, A, B](l, Node(r, y)) | |
| } | |
| } |
!SLIDE
!SLIDE