Skip to content

Instantly share code, notes, and snippets.

import scala.quoted.*
trait Bar {
type X
}
object Foo {
def makeImpl[A : Type](a: Expr[A])(using Quotes): Expr[Any] = {
import quotes.reflect.*
val tree = TypeSelect(a.asTerm, "A").tpe.asType match {
;; -*- lexical-binding: t; -*-
(require 'rx)
(defvar rackunit-runner "raco")
(defun rackunit-goto ()
(interactive)
(let
((marker
object Example {
def failsHorribly[T1 <: Tuple, T2 <: Tuple](f: () => Either[Unit, Tuple.Concat[T1, T2]])(using size: Tuple.Size[T1]): () => Either[Unit, T2] = {
() => {
f() match {
case Left(_) => Left(())
case Right(item) => Right(item.drop(size).asInstanceOf[T2])
}
}
}
#[derive(Debug)]
struct Tone {
position: isize
}
impl cubeb::StreamCallback for Tone {
type Frame = cubeb::MonoFrame<i16>;
fn data_callback(&mut self, input: &[cubeb::MonoFrame<i16>], _: &mut [cubeb::MonoFrame<i16>]) -> isize {
self.position += 1;
def tree[F[_[_]]](implicit T: BirecursiveT[F]): Algebra[SExp, F[RTree[String, ?]]] = {
case Nil => RTree.Node(List.empty[F[RTree[String, ?]]]).embed
case True => RTree.Leaf("t").narrow[F[RTree[String, ?]]].embed
case Int(v) => RTree.Leaf(v.toString).narrow[F[RTree[String, ?]]].embed
case Keyword(k) => RTree.Leaf(s":$k").narrow[F[RTree[String, ?]]].embed
case Symbol(s) => RTree.Leaf(s"'$s").narrow[F[RTree[String, ?]]].embed
case Char(c) => RTree.Leaf(s"?$c").narrow[F[RTree[String, ?]]].embed
case Pair(l, r) => r.project match {
case RTree.Node(t) => RTree.Node(l :: t).embed
@yilinwei
yilinwei / sexp.scala
Created June 10, 2017 15:06
problem.scala
val show: Algebra[SExp, Option[String] => String] = {
case True => _ => "t"
case Symbol(s) => _ => s"'$s"
case Keyword(k) => _ => s":$k"
case Char(c) => _ => s"?$c"
case Int(v) => _ => v.toString
case Nil => {
case None => "nil"
case Some(p) => s"$p)"
}
Expr(Block(List(Import(Select(Ident(cats), cats.implicits), List(ImportSelector(termNames.WILDCARD, 941, null, -1))), ValDef(Modifiers(IMPLICIT), TermName("F"), TypeTree().setOriginal(AppliedTypeTree(Ident(cats.MonadCombine), List(TypeTree().setOriginal(Ident(cats.tests.ListWrapper))))), Select(Ident(cats.tests.ListWrapper), TermName("monadCombine"))), ValDef(Modifiers(IMPLICIT), TermName("L"), TypeTree().setOriginal(AppliedTypeTree(Select(Select(This(TypeName("cats")), cats.package), TypeName("Monoid")), List(TypeTree().setOriginal(AppliedTypeTree(Ident(cats.tests.ListWrapper), List(TypeTree().setOriginal(Select(Ident(scala), scala.Int)))))))), TypeApply(Select(Ident(cats.tests.ListWrapper), TermName("monoid")), List(TypeTree().setOriginal(Select(Ident(scala), scala.Int))))), ValDef(Modifiers(IMPLICIT), TermName("F"), AppliedTypeTree(Ident(TypeName("MonadCombine")), List(Ident(TypeName("ListWrapper")))), Select(Ident(TermName("ListWrapper")), TermName("monadCombine"))), ValDef(Modifiers(IMPLICIT), TermName("
package cats
import cats.macros.ImplicitResolutionSpec
import cats.functor._
final class ImplicitResolutionTests extends ImplicitResolutionSpec {
canResolve[String, Monoid] {
import cats.implicits._
package fs2
trait Chunk2[@specialized(Boolean, Int, Long, Float) +A] {
def map[B](f: A => B): Chunk2[B]
}
object Chunk2 {
object Booleans {
@yilinwei
yilinwei / free.scala
Last active April 2, 2017 13:25
Free example
object MTL {
import cats._
import cats.free._
import cats.data._
import cats.implicits._
sealed trait DSL[A]
case class Get[A]() extends DSL[A]