Skip to content

Instantly share code, notes, and snippets.

sealed trait Free[+F[_], A]
object Free {
def eval[F[_], A](fa: Free[F, A])(implicit F: Monad[F]): F[A] = {
type State = (Free[F, Any], List[Any => Free[F, Any]])
def go(s: State): F[Either[State, Any]] = s match {
case (current, stack) =>
current match {
case Done(a) =>
stack match {
case Nil =>
///////////////////////////////////////////////////////////////////
// STEP 1 - Evaluation by need monad
///////////////////////////////////////////////////////////////////
import scala.annotation.unchecked.{ uncheckedVariance => uV }
final class Need[+A](private[this] var thunk: Need.Thunk[A @uV]) { A =>
import Need._
def value: A = thunk match {
case Done(x) => x
  1. def hash(a: A): Int makes me sad. What about hashing to 64 bits or SL2 Fp?
  2. def MapHash[A, B: Hash]: Hash[Map[A, B]] is a bit odd. Why not A: Hash?
  3. reflexiveLaw + symmetryLaw + transitivityLaw is too weak for "equality". This defines a general equivalence relationship only.
  4. val AnyEqual: Equal[Any] is worrisome, considering all the resolution bugs!
  5. val DoubleEqual: Equal[Double] should be implemented using java.lang.Double.doubleToRawLongBits.
  6. A combintation of [trait Ord[-A] extends Equal[A]](https://github.com/zio/zi
// This sums up my understanding of
// https://github.com/lampepfl/dotty/issues/9359
// and https://github.com/lampepfl/dotty/issues/8430
// == on AnyVal does not imply singleton type equality
class Test[A](val x: Int) extends AnyVal
def coerce1[A, B](a: A): B = {
val x = new Test[A](1)
val y = new Test[B](1)
trait CharReader {
def current(): Int
def advance(): Unit
}
object CharReader {
final val EOF: Int = -1
final val EOB: Int = -2
@silent final class FromString(val text: String, end: Int) extends CharReader {
var index = 0
from itertools import *
# Compute our D(pi) function
elements = {}
for p in permutations([1,2,3,4]):
d = [i+1 for i in range(3) if p[i] > p[i + 1]]
elements[p] = frozenset(d)
# Make a graph with the given pi < tau relation.
graph = {}
import cats.Eval
import cats.syntax.all._
trait Eq[A] {
def eqv(x: A, y: A): Eval[Boolean]
}
trait Eq1[F[_]] {
def eqv1[A](x: F[A], y: F[A])(implicit A: Eq[A]): Eval[Boolean]
}
import cats.Eq
trait Eq1[F[_]] {
def eqv1[A](x: F[A], y: F[A])(implicit A: Eq[A]): Boolean
}
final case class Fix[F[_]](unfix: F[Fix[F]])
object Fix {
implicit def eqv[F[_]: Eq1]: Eq[Fix[F]] = new Eq[Fix[F]] {
def eqv(x: Fix[F], y: Fix[F]): Boolean =
#if __ENDIAN_LITTLE__
# define NATIVE_LITTLE_ENDIAN 1
#endif
#if __LITTLE_ENDIAN__
# define NATIVE_LITTLE_ENDIAN 1
#endif
#define BLAKE2S_BLOCKBYTES 64
from collections import namedtuple
Add = namedtuple('Add', 'args')
Xor = namedtuple('Xor', 'left right')
Rot = namedtuple('Rot', 'left right')
Input = namedtuple('Input', 'name')
Const = namedtuple('Const', 'value')
Set = namedtuple('Set', 'var expr')
IV0p = 0x6b08e647