Skip to content

Instantly share code, notes, and snippets.

View pchiusano's full-sized avatar

Paul Chiusano pchiusano

View GitHub Profile
@pchiusano
pchiusano / Chain.hs
Last active August 29, 2015 14:25
Stream processing API
{-# Language GADTs #-}
module Chain where
data Chain k a b where
Empty :: Chain k a a
Chain :: k a x -> Chain k x b -> Chain k a b
@pchiusano
pchiusano / .vimrc
Created July 23, 2015 02:08
My vimrc
colorscheme solarized
set background=light
set undofile
set lbr
set wrap
set guioptions-=T "remove toolbar
set ignorecase
set smartcase
set incsearch
set scrolloff=2
@pchiusano
pchiusano / Vector.hs
Last active December 15, 2015 14:13
A fast, immutable sequence type
-- |
-- Fast sequence type based on skewed array-indexed tries
-- with large branching factor, `B`.
--
-- Asymptotics (assuming vector of size `N`):
-- O(1) worst-case access to indices [0,B)
-- O(1) average-case access to indices [N-B,N)
-- O(log_B(i)) worst-case access to index i
-- O(1) amortized snoc, O(log_B(N)) worst case
--
@pchiusano
pchiusano / streams.scala
Last active August 29, 2015 14:23
Stream API
package streams
trait Free[+F[_],+A] {
import Free._
def flatMap[F2[x]>:F[x],B](f: A => Free[F2,B]): Free[F2,B] = Bind(this, f)
def map[B](f: A => B): Free[F,B] = Bind(this, f andThen (Free.Pure(_)))
}
object Free {
case class Pure[A](a: A) extends Free[Nothing,A]
case class Eval[F[_],A](fa: F[A]) extends Free[F,A]
@pchiusano
pchiusano / Edit.hs
Last active August 29, 2015 14:22
A type for tracking well-typed edits to a codebase, equipped with a commutative merge function
module Edit where
import qualified Data.Map as Map
import Data.Map (Map)
import qualified Data.Set as Set
import Data.Set (Set)
import Data.List
import Data.Maybe
-- | Invariant: if a hash is open, its dependents in the `Edit` must also be open
@pchiusano
pchiusano / scalaz-stream-design.markdown
Last active August 29, 2015 14:22
WIP design for new scalaz-stream core

All right, here we go! The API is quite a bit different than what we have currently, but it's simpler to use, more general, and the implementation can be much more efficient. The encoding for Tee, Process1, Channel is greatly simplified, these become just regular functions, rather than a Process[F,_] with a funky F. Stepping a Process is now a first-class concept, exposed publicly, in a safe way. The resulting style looks a lot like ordinary list processing, and doing things like a 3-way or N-way merge are trivial.

The algebra and the canonical model for this algebra are given in the attached streams.scala. The algebra for streams is given by the trait Stream[P[+_[_],+_]], and there's a canonical instance, Stream[NF], which specifies what the operations mean. A couple notes:

  • The Process[F,A] data type we have currently would have a Stream instance. (Name of Stream TBD)
  • The Chunk type is TBD
  • Free is just the free monad (well, one formulation of it)
  • I still have some uncert
@pchiusano
pchiusano / errors.markdown
Created May 27, 2015 16:29
Nix / cabal not picking up modifications to local package

I have two projects, shared and node, where node depends on shared, basically following the instructions here. What I notice is that nix is failing to pick up the latest version of shared when building node. It's very strange, because shared will be rebuilt, but then I get compilation errors in node that indicate to me that it's still using an older version of shared.

Here's my directory structure:

shared/
  default.nix
  shell.nix
  unison-shared.cabal
  ...
@pchiusano
pchiusano / default.nix
Created May 21, 2015 03:12
Error while attempting vanilla build off nixpkgs master
{ mkDerivation, reflex, reflex-dom, stdenv, unison-shared }:
mkDerivation {
pname = "unison-editor";
version = "0.1";
src = ./.;
isLibrary = true;
isExecutable = true;
buildDepends = [ reflex reflex-dom unison-shared ];
homepage = "http://unisonweb.org";
description = "The Unison programming language and platform";
@pchiusano
pchiusano / cabal2nix.markdown
Last active August 29, 2015 14:21
Why on earth does cabal2nix depend on docbook, subversion, xmlto, and git?
$ nix-env -f ../nixpkgs -i -A haskellngPackages.cabal2nix
installing ‘cabal2nix-20150518’
  /nix/store/pnqg8y2zrhd2vbg8kax44a2cwf8a9kjc-xmlto-0.0.26.drv
  /nix/store/sam969jfhv1ppaj14246sj68jbhfvfr5-opensp-1.5.2.drv
  /nix/store/7pz98nf42b0v2px4fama3vkhi0r0niqx-docbook2X-0.8.8.drv
  /nix/store/0f9xksnvkbwnfl6m73bjjjq589m77q6v-git-2.4.1.drv
  /nix/store/271vx0jlj56hvs7x80a6bibmijdy7y5n-subversion-1.8.13.drv
  /nix/store/40jlir08xpbm18iyv1q5aaslcc4hnxq7-nix-prefetch-scripts.drv
 /nix/store/dra4d7713cd86k0j30pwq4yp0lrs29fr-cabal2nix-20150518.drv
@pchiusano
pchiusano / cabal-default.nix
Last active August 29, 2015 14:21
Nix setup
# generic builder for Cabal packages
{ stdenv, fetchurl, lib, pkgconfig, ghc, Cabal, jailbreakCabal, glibcLocales
, gnugrep, coreutils, hscolour, cpphs
, enableLibraryProfiling ? false
, enableSharedLibraries ? false
, enableSharedExecutables ? false
, enableStaticLibraries ? true
, enableCheckPhase ? stdenv.lib.versionOlder "7.4" ghc.version
, enableHyperlinkSource ? true