Skip to content

Instantly share code, notes, and snippets.

View pchiusano's full-sized avatar

Paul Chiusano pchiusano

View GitHub Profile
@pchiusano
pchiusano / Explorer.hs
Created October 30, 2015 15:39
Reflex explorer wip
{-# LANGUAGE RecursiveDo #-}
module Unison.Explorer where
import Data.Semigroup
import Control.Monad.Fix
import Reflex.Dom
import Unison.Dimensions (X(..),Y(..))
import qualified Unison.Signals as Signals
@pchiusano
pchiusano / error.markdown
Created October 29, 2015 17:58
GHC holes have useless types

Got this recently:

Found hole ‘_view’ with type: t2 -> t3 -> t1
Where: ‘t1’ is a rigid type variable bound by
            the inferred type of view :: t2 -> t3 -> t1
            at src/Unison/Explorer.hs:38:11
       ‘t2’ is a rigid type variable bound by
            the inferred type of view :: t2 -> t3 -> t1
 at src/Unison/Explorer.hs:38:11
@pchiusano
pchiusano / boston-haskell-notes.markdown
Last active February 28, 2018 15:38
Notes from Boston Haskell talk on csound-expression

Video of the talk - recording didn't come out that great unfortunately.

The Gitter chat room for csound-expression

Quick-start guide for csound-expression. The library just needs a csound binary on your path somewhere. It communicates with csound just by passing generated .csd files to the csound binary. Binaries are available for pretty much every platform, and on Ubuntu/Debian you can sudo apt-get install csound csound-gui.

Once you have csound, you can just cabal install csound-expresion or cabal install csound-catalog (assuming you have Haskell and cabal installed). I recommend doing cabal install csound-catalog, since that will pull in the csound-expression library and the library of great instruments that Anton has put together.

Other res

@pchiusano
pchiusano / Score.hs
Last active October 22, 2015 15:13
Alternate Score type for csound-expression
{-# Language DeriveFoldable #-}
{-# Language DeriveFunctor #-}
{-# Language DeriveTraversable #-}
{-# Language TypeFamilies #-}
module Score where
import Csound.Base
data Params = Params { duration0 :: !Double, volume0 :: D, sustain0 :: !Double }
@pchiusano
pchiusano / Catenable.hs
Last active February 11, 2017 04:40
Trivial catenable sequence with amortized O(1) uncons and unsnoc
module Catenable (Catenable, empty, singleton, toList, fromList, uncons, unsnoc) where
import Data.List (foldl')
import Control.Monad
-- | Trivial catenable sequence. Supports O(1) append, and (amortized)
-- O(1) `uncons`, and `unsnoc`, such that walking the sequence via
-- N successive `uncons` steps or N `unsnoc` steps takes O(N). Like a
-- difference list, conversion to a `[a]` takes linear time, regardless
-- of how the sequence is built up.
@pchiusano
pchiusano / inversion-of-control.scala
Last active September 30, 2015 01:49
Some simple primitives for inverting control in FS2
trait Ack[+W]
object Ack {
case class Accept(unprocessedSize: Int) extends Ack[Nothing]
case class Halt(unprocessed: Seq[W]) extends Ack[W]
case class Fail(err: Throwable, unprocessed: Seq[W]) extends Ack[W]
}
trait Input[+W]
object Input {
case class Send[W](chunk: Chunk[W]) extends Input[W]
@pchiusano
pchiusano / error.log
Created September 3, 2015 19:12
Epic compile error from Scala
> compile
[info] Compiling 1 Scala source to /Users/pchiusano/Dropbox/projects/scalaz-stream/target/scala-2.11/classes...
[error] /Users/pchiusano/Dropbox/projects/scalaz-stream/src/main/scala/streams/Process1.scala:27: polymorphic expression cannot be instantiated to expected type;
[error] found : [F(in method run)(in method run)(in method run)(in method run)(in method run)(in method run)(in method run)(in method run)[_], I2(in method run)(in method run)(in method run)(in method run)(in method run)(in method run)(in method run)(in method run) <: I]streams.Stream.Handle[F(in method run)(in method run)(in method run)(in method run)(in method run)(in method run)(in method run)(in method run),I] => streams.Pull[F(in method run)(in method run)(in method run)(in method run)(in method run)(in method run)(in method run)(in method run),O,streams.Stream.Handle[F(in method run)(in method run)(in method run)(in method run)(in method run)(in method run)(in method run)(in method run),I2(in method run)(in method run)(in
@pchiusano
pchiusano / Streams.scala
Created July 31, 2015 19:09
Scala Streams API
trait Stream[S[+_[_],+_]] { self =>
// list-like operations
def empty[A]: S[Nothing,A] = emits[A](Chunk.empty)
def emits[A](as: Chunk[A]): S[Nothing,A]
def append[F[_],A](a: S[F,A], b: => S[F,A]): S[F,A]
@pchiusano
pchiusano / debug.hs
Created July 30, 2015 01:25
Debugging trick in Haskell
module Foo where
import Debug.Trace
traceByteString :: String -> ByteString -> ByteString
traceByteString msg b | traceShow b False = undefined
traceByteString msg b = b
@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