Skip to content

Instantly share code, notes, and snippets.

Paul Chiusano pchiusano

Block or report user

Report or block pchiusano

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
pchiusano / state.u
Created May 8, 2019
Abilities in Unison
View state.u
ability State s where
put : s ->{State s} ()
get : {State s} s
state : s -> Effect (State s) a -> a
state s eff = case eff of
{ State.get -> k } -> handle (state s) in k s
{ State.put snew -> k } -> handle (state snew) in k ()
{ a } -> a
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
You can’t perform that action at this time.