Skip to content

Instantly share code, notes, and snippets.

View paulp's full-sized avatar
🤫

Paul Phillips paulp

🤫
  • CAZ, Inc.
  • Cascadia Autonomous Zone
View GitHub Profile
@paulp
paulp / integer-division.z3
Created July 4, 2021 21:13 — forked from Rufflewind/integer-division.z3
Truncated integer division in Z3
(declare-fun a () Int)
(declare-fun b () Int)
(declare-fun c () Int)
;; (assert (= a (div -7 -3)))
;; (assert (= b (div 7 -3)))
;; (assert (= c (div -7 3)))
;; (assert (= a (mod -7 -3)))
;; (assert (= b (mod 7 -3)))
;; (assert (= c (mod -7 3)))
@paulp
paulp / package.scala
Created January 16, 2016 23:19 — forked from zraffer/package.scala
a few operations with functors
package object types {
import scala.language.reflectiveCalls
import scala.language.higherKinds
// quantifiers aka (co)ends
type Forall[+F[_]] = { def apply[X]: F[X] }
type Exists[+F[_]] = F[_]
// basic categorical notions
@paulp
paulp / notes.md
Last active December 26, 2015 18:49 — forked from jrudolph/notes.md
  • Thesis: Problem is the language as much as the implementation of the compiler
    • Big problem is cyclic dependency in the typer where type inference and type-checking and implicit search mutually depend on each other. In other words: Can you write an interpreter without also writing a typer that at least implements type inference and implicit search. Can you do implicit search without implementing all of the type checker? Type inference and implicit search must be disentangled. They know that in scala too, except that it will be close to impossible. Note that disentanglement doesn't preclude interaction, but it has to flow through much narrower, explicit, disciplined channels.
    • Consequence if this is true: If you want to simplify the compiler you would have to identify how to simplify the language to break up those cycles **There are innumerable simplifications available in the compiler which require nothing but sane software engineering. If you want to minimize the ESSENTIAL complexity
package tuple
import language.experimental.macros
import language.dynamics
import scala.reflect.macros.Context
sealed trait ~[+A, +B]
private[tuple] object TupleMacros {
@paulp
paulp / HOF.scala
Last active December 15, 2015 14:59 — forked from samskivert/HOF.scala
// Say we have a List of names and we would like to find all those names where "am" occurs:
{
// LINQ
// string[] names = { "Sam", "Pamela", "Dave", "Pascal", "Erik" };
// List<string> filteredNames = names.Where(c => c.Contains("am"))
// .ToList();
// Java Streams
// String[] names = {"Sam","Pamela", "Dave", "Pascal", "Erik"};
// List<String> filteredNames = stream(names)
@paulp
paulp / devirtualized.md
Created October 1, 2012 22:55 — forked from c9r/devirtualized.md
De-virtualized Collections

De-virtualized Collections

De-virtualizing abstract collections would increase performance and decrease bytecode bloat for common use cases–without tying the hands of implementors. Conceptually, operations on abstract collections become syntactic sugar for inlined code templates. You opt-in to dynamic behavior by choosing subtypes that override extension methods with virtual ones. The root collections then become an encapsulation of their elements, but not an abstraction over operations on those elements; you can still perform such operations on these collections, but the compiler statically binds the implementation rather than indirecting to the run-time type's vtable-provided version. Collection sub-families–parallel, non-strict, and the like–override generic extension methods with virtual ones, and any value statically typed to such a collection works in the usual object-oriented way.

Sample de-virtualized collection hierarchy

import collection.generic.CanBuildFrom
import language.im
@paulp
paulp / devirtualized.md
Created September 17, 2012 03:38 — forked from c9r/devirtualized.md
De-virtualized Collections

De-virtualized Collections

De-virtualizing abstract collections would increase performance and decrease bytecode bloat for common use cases–without tying the hands of implementors. Conceptually, operations on abstract collections become syntactic sugar for inlined code templates. You opt-in to dynamic behavior by choosing subtypes that override extension methods with virtual ones. The root collections then become an encapsulation of their elements, but not an abstraction over operations on those elements; you can still perform such operations on these collections, but the compiler statically binds the implementation rather than indirecting to the run-time type's vtable-provided version. Collection sub-families–parallel, non-strict, and the like–override generic extension methods with virtual ones, and any value statically typed to such a collection works in the usual object-oriented way.

Sample de-virtualized collection hierarchy

import collection.generic.CanBuildFrom
import language.im
@paulp
paulp / scala-merge-integration.sh
Created December 6, 2011 21:42 — forked from jsuereth/scala-merge-integration.sh
Merge script to make sure develop commits actually build before pushing to master.
#!/usr/bin/env bash
#
# ^-- don't assume bash is in /bin
# we need a git library of stuff like this, since there are lots
# of ways to get it subtly wrong
git_branch_exists () {
git show-ref --verify --quiet refs/heads/$1
}
@paulp
paulp / x.js
Created January 31, 2011 20:03 — forked from tssm0n/x.js
CmdUtils.CreateCommand({
names: ["java"],
arguments: [{role: "object",
nountype: noun_arb_text,
label: "search criteria"}],
icon: "http://www.sun.com/favicon.ico",
preview: "Searches The Java 6 API.",
help: "Enter the name of the Java class or package for which you would like to see the documentation.",
author: {name: "KS", email: "tss@cornbread.com"},
trait Cloneable[+T <: AnyRef] extends AnyRef {
def create(): T
override def clone(): T = create()
}
class A(var a: Int) extends Cloneable[A] {
def create(): A = new A(a)
}
class B(aa: Int, var b: Int) extends A(aa) with Cloneable[B] {