Skip to content

Instantly share code, notes, and snippets.

Paul Chiusano pchiusano

View GitHub Profile
pchiusano / .ctags
Last active Mar 24, 2018
The ultimate ctags regex for Scala
View .ctags
--regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*(private|protected)?[ \t]*class[ \t]+([a-zA-Z0-9_]+)/\4/c,classes/
--regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*(private|protected)?[ \t]*object[ \t]+([a-zA-Z0-9_]+)/\4/c,objects/
--regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*(private|protected)?[ \t]*case class[ \t]+([a-zA-Z0-9_]+)/\4/c,case classes/
--regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*(private|protected)?[ \t]*case object[ \t]+([a-zA-Z0-9_]+)/\4/c,case objects/
--regex-scala=/^[ \t]*((abstract|final|sealed|implicit|lazy)[ \t]*)*(private|protected)?[ \t]*trait[ \t]+([a-zA-Z0-9_]+)/\4/t,traits/
--regex-scala=/^[ \t]*type[ \t]+([a-zA-Z0-9_]+)/\1/T,types/
--regex-scala=/^[ \t]*((@annotation.tailrec|@tailrec|@inline)[ \t]*)*((abstract|final|sealed|implicit|lazy|private|protected)[ \t]*)*def[ \t]+([a-zA-Z0-9_]+)/\5/m,methods/
--regex-scala=/^[ \t]*((abstract|final|sealed|implicit|la
pchiusano / Interpreters.scala
Created Sep 21, 2017
Code for Scala World 2017 talk on eliminating interpreter overhead via partial evaluation
View Interpreters.scala
package scalaworld.interpreters
This file shows a simple language, an interpreter, and two
partial evaluators for that language, along with a profiling suite.
trait Expr // denotes a Vector[Double] => Vector[Double]
object Expr {
pchiusano / QuickProfile.scala
Created Jun 13, 2017
Adaptive profiling for JVM, runs evaluation until runtime stabilizes
View QuickProfile.scala
object QuickProfile {
def timeit(label: String, threshold: Double = 0.05)(action: => Long): (String, Double) = {
var N = 16L
var i = 0
var startTime = System.nanoTime
var stopTime = System.nanoTime
var sample = 1e9
var K = 0L
var ok = true
pchiusano / Pull.hs
Last active May 23, 2017
Stream processing scoping primitives
View Pull.hs
data Free f r
= Pure r
| Fail Err
| Eval (f r)
| forall x . Bind (Free f x) (Either Err x -> Free f r)
type Pull f o r = Free (StreamF o) r
data StreamF o x where
pchiusano / fastcodec.scala
Created Apr 2, 2017
Fast binary encoding and decoding interfaces
View fastcodec.scala
package fastcodecs
import java.nio.{ByteBuffer, BufferUnderflowException}
abstract class Decoder[+A] {
* Read a value from the `ByteBuffer`, advancing the offset if successful.
* Result is stored in `result`, unboxed if possible.
* On failure, a `DecodingFailure` is thrown.
pchiusano / Streams.hs
Last active Feb 21, 2018
Another effectful stream representation
View Streams.hs
{-# Language ExistentialQuantification #-}
{-# Language GADTs #-}
{-# Language RankNTypes #-}
{-# Language ScopedTypeVariables #-}
import Control.Monad
import Control.Applicative
import Data.List hiding (uncons)
import Data.Time
pchiusano / traverse.scala
Created Mar 23, 2017
Another encoding of `Traverse` in terms of `mapAccumulate`
View traverse.scala
* In this version of `Traverse`, sequencing always goes through `List` (or some other canonical sequence type),
* which can be done in a stack-safe manner using a balanced fold as in
* It's quite nice that `sequence` and `traverse` are now derived functions.
trait Traverse[F[_]] extends Functor[F] {
/** Inefficient but correct implementation of `toList` in terms of `mapAccumulate`. */
def toList[A](f: F[A]): List[A] = mapAccumulate(f, List())((a, rbuf) => (a, a :: rbuf))._2.reverse
/** The only function that must be implemented. Must be consistent with `map`. */
pchiusano / rfc.markdown
Created Feb 21, 2017
Rough draft of v3 of Unison distributed programming APIs
View rfc.markdown

Unison computations can hop between nodes, can fail, can be forked to execute asynchronously, and can be supervised:

-- Promote a pure value to `Remote`
Remote.pure :  a . a -> Remote a

-- Sequencing of remote computations
Remote.bind :  a b . (a -> Remote b) -> Remote a -> Remote b

-- The current node where the computation is executing
pchiusano / map-reduce.hs
Last active Jan 12, 2017
map reduce on as many nodes as you want in 10 lines of Unison code
View map-reduce.hs
-- note, syntax here is Unison, just using .hs extension to get some syntax highlighting
-- The mapping function may spawn subcomputations on different nodes,
-- and the reduction function is done in parallel, building a balanced tree
-- of operations. Computation fails if any step takes longer than timeout
mapreduce : forall a b
. Duration -> (a -> Remote b) -> b -> (b -> b -> b) -> Vector a
-> Remote b
mapreduce timeout f z op vs = do Remote
futures := Remote.traverse (f `and-then` Remote.start timeout) vs
pchiusano / fs2-0.9-release-announcement.markdown
Last active Sep 20, 2016
FS2: Functional Streams for Scala 0.9 Official Release Announcement
View fs2-0.9-release-announcement.markdown

Hi all!

After a very lengthy period of development and testing, FS2 (formerly scalaz-stream) version 0.9 is finally out! Here's how to get it.

For this release, the library has undergone a major redesign. Check out the migration guide for more info, and also the shiny new user guide. Going forward, we expect the API of the library will be quite stable and hope it becomes one of the bedrock libraries of the Scala ecosystem. The 0.9 series has already seen production use as well as a huge amount of testing during the development process; we feel very good about recommending people upgrade.

You can’t perform that action at this time.