Skip to content

Instantly share code, notes, and snippets.

  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
import scala.util.control.NonFatal
type && [F[_], G[_]] = [x] =>> F[x] & G[x]
trait CombinatorErrors[E] {
def tupleLeft(e: E): E
def tupleRight(e: E): E
def tupleBoth(e1: E, e2: E): E
}
import scala.util.control.NonFatal
trait CombinatorErrors {
type Error
def tupleLeft(e: Error): Error
def tupleRight(e: Error): Error
def tupleBoth(e1: Error, e2: Error): Error
}
trait Reader[-C, +A] { A =>