Skip to content

Instantly share code, notes, and snippets.

Avatar

Erik Osheim non

  • Providence / Philly
View GitHub Profile
View ack.scala
package ack
import cats.Eval
import spire.math.SafeLong
object Ackermann {
import SafeLong.{zero, one}
// requires m >= 0 and n >= 0
def run(m: SafeLong, n: SafeLong): Eval[SafeLong] =
@non
non / seeds.md
Last active Apr 5, 2022
Simple example of using seeds with ScalaCheck for deterministic property-based testing.
View seeds.md

introduction

ScalaCheck 1.14.0 was just released with support for deterministic testing using seeds. Some folks have asked for examples, so I wanted to produce a Gist to help people use this feature.

simple example

These examples will assume the following imports:

@non
non / seethru.scala
Last active Feb 13, 2018
nested opaque types demo
View seethru.scala
package object demo {
opaque type Collection[A] = Array[A]
object Collection {
opaque type Pointer[A] = Int
object Pointer {
def first(c: Collection[A]): Option[Pointer[A]] =
if (c.length > 0) Some(0) else None
@non
non / Diagonal.scala
Last active Feb 13, 2018
Initial thoughts on creating efficient ways to index into arbitrary enumerations of all values of a type.
View Diagonal.scala
package kronecker
import spire.implicits._
/**
* Utilities for doing diagonalization in N dimensions.
*
* The goal here is to be able to support diagonalizations for
* arbitrary tuples, e.g. Tuple2, Tuple3, Tuple9, etc. The "dimension"
* (or "dim") represents the arity of the tuple: dim=2 would
@non
non / JavapPlugin.scala
Created Jan 29, 2018
Slouching toward a functioning SBT plugin.
View JavapPlugin.scala
package sbtjavap
import sbt._
import Keys._
import complete.DefaultParsers.StringBasic
import scala.sys.process.Process
object Plugin extends AutoPlugin {
object autoImport {
@non
non / analysis.md
Last active Jan 2, 2018
Some notes about the interaction of SIP-23 with specialization.
View analysis.md

introduction

I was asked to consider how specialization should interact with SIP-23. Here is a quick test I did with some thoughts on where we are now versus where we should be.

See tlc.scala for the code and tlc.bytecode for the Java bytecode that code produced (using Typelevel Scala with the -Yliteral-types flag enabled).

View sipzz.md

SIP-ZZ - NewType Classes

Introduction

This is a proposal to introduce syntax for classes in Scala that can get completely inlined, so operations on these classes have zero overhead compared to external methods. Some use cases for inlined classes are:

  • Inlined implicit wrappers. Methods on those wrappers would be
@non
non / builtins.txt
Last active May 12, 2017
List of classes/traits in Scala's standard library that are probably worth supporting via type classes. The implication being that other types (e.g. GenSeq) are not worth supporting directly. Suggested additions welcome!
View builtins.txt
scala
Array
BigDecimal
BigInt
Boolean
Byte
Char
Double
Float
FunctionN...
View NotFantastic.scala
// 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 Feb 20, 2022
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.
View laws.md

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