Skip to content

Instantly share code, notes, and snippets.

// this code demonstrates unsoundness in scala (tested in 2.11 and 2.12)
//
// it seems like scala is checking that the return type is a Pipe[_]
// but not a Pipe[E]; maybe due to erasure?
sealed abstract class Pipe[E]
case class Single[E](elem: E) extends Pipe[E]
case class Double[A, B](a: Pipe[A], b: Pipe[B]) extends Pipe[(A, B)]
object Pipe {
@non
non / laws.md
Last active February 20, 2022 00:26
I feel like conversations around laws and lawfulness in Scala are often not productive, due to a lack of rigor involved. I wanted to try to be as clear and specific as possible about my views of lawful (and unlawful) behavior, and what I consider a correct and rigorous way to think about laws (and their limits) in Scala.

Laws

A law is a group of two or more expressions which are required to be the same. The expressions will usually involve one or more typed holes ("inputs") which vary.

Some examples:

x.map(id) === x
@non
non / mark.scala
Created January 3, 2017 15:00
Scala solver for Mark Dominus' arithmetic puzzle (http://blog.plover.com/math/17-puzzle.html).
package mark
import spire.math.{ Rational => Q }
object Solver2 {
case class Op(name: String, run: (Q, Q) => Option[Q])
val ops: List[Op] = List(
Op("+", (x, y) => Some(x + y)),
### higher profile independent games
868-hack: really fun glitchy hacking game
diaries of a spaceport janitor: meditative weirdness, cryptic walking sim
ftl: roguelike space adventure game #1
out there: rogulike space exploration game #2
hadean lands: alechmical exploration text adventure
sunless sea: steampunk underground sailing game
this war of mine: too real refugee-during-wartime sim
vvvvvv: light-hearted/abstract platform puzzle game
## ELEVEN TWINE GAMES
16 Ways To Kill A Vampire At McDonalds
by @AbigailMoment (Abigail Corfman)
https://ifcomp.org/1553/content/16%20Ways%20To%20Kill%20A%20Vampire%20At%20McDonalds.html
humorous game about a vampire killer's night off
My Father's Long, Long Legs
@WarrenIsDead (Michael Lutz)
http://correlatedcontents.com/misc/Father.html
@non
non / beala.scala
Created May 9, 2016 00:07
Demo using Cats/Dogs to implement lazy memoization, similar to this Haskell gist: https://gist.github.com/beala/d871ae8397167e7035f218a25ddf87dd
package beala
import dogs._
object Beala {
// ironically dogs doesn't support unsafe operations by default,
// so we have to build them ourselves (since we know our stream
// is infinite and will always have elements).
def head[A](as: Streaming[A]): A =
@non
non / modulus.scala
Created April 6, 2016 05:06
Quick little modular arithmetic example using Spire.
package modulus
import spire.algebra.{ Eq, Field }
import spire.math.Polynomial
class Mod(val residue: Long, val modulus: Long) { lhs =>
def +(rhs: Mod): Mod = {
require(lhs.modulus == rhs.modulus)
Mod(lhs.residue + rhs.residue, modulus)
package array
class Test {
def callSize(arr: Array[Int]): Int = arr.size
def callLength(arr: Array[Int]): Int = arr.length
}
package du
import cats._
import cats.implicits._
import cats.data.Streaming
import java.io.File
/**
* This is a port of this Haskell code to Scala using Cats.
*
@non
non / zg.scala
Last active October 21, 2015 22:48
package zg
import spire.random.Generator
/**
* ImGen is an immutable RNG.
*
* It "hides" Generator's mutability through next.
*/
class ImGen[G <: Generator](gen: G) {