Skip to content

Instantly share code, notes, and snippets.

View sleexyz's full-sized avatar

Sean Lee sleexyz

View GitHub Profile
signature MONOID =
sig
type t
val append : t * t -> t
val zero : t
end
structure Additive =
struct
type t = int
class ContextBoundsSyntax {
trait Monoid[A] {
def zero:A
def append (a:A, b:A) : A
}
implicit object AdditiveInt extends Monoid[Int] {
def zero = 0
def append (a:Int, b:Int) = a + b
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables #-}
module DiagramsTidal where
import Sound.Tidal.Pattern hiding (square)
import Sound.Tidal.Time
import Sound.Tidal.Utils
@sleexyz
sleexyz / default.nix
Last active August 6, 2016 15:59
for librosa
with import <nixpkgs> {}; {
pyEnv = stdenv.mkDerivation {
name = "py";
buildInputs = [
stdenv
python27
blas
gcc
ffmpeg
] ++ (with python27Packages; [
{-# LANGUAGE RecordWildCards #-}
data Person = Person {name :: String, address :: String}
me = Person {name = "Sean", address = "315 Seigel St"}
foo :: String
foo =
let Person{..} = me
in
-- How do we make a tuple that's functorial over the first parameter?
-- We can't!
data Tup a b = Tup a b
instance Functor (Tup a) where
fmap f (Tup x y) = Tup x (f y)
instance Functor (Tup a) where
fmap f (Tup x y) = Tup x (f y)
let foo : int =
2 + 2
let bar : float =
2.0 +. 2.0
let baz : string =
string_of_int foo ^ string_of_float bar
// demonstration of ocaml's lack of ad-hoc polymorphism
s.options.numBuffers = 1024 * 16;
s.waitForBoot{
Routine{
include("SuperDirt");
2.wait;
SuperDirt.start;
}.play
}
@sleexyz
sleexyz / AnnotatedFix.hs
Created June 23, 2016 19:32
Fixed point combinator derivied without knot-tying, via recursive types
{-# LANGUAGE GADTSyntax #-}
-- | Derivation of fix without general recursion
-- | Transliteration of PFPL 2nd Ed, pp. 180
module AnnotatedFix where
newtype Self t where
Fold :: (Self t -> t) -> Self t
@sleexyz
sleexyz / Fix.hs
Created June 23, 2016 19:29
Fixed point combinator derived without knot-tying, via recursive types
newtype Self t = Fold { unfold :: Self t -> t}
fix :: (a -> a) -> a
fix f = unroll . Fold $ f . unroll
unroll :: Self t -> t
unroll e = unfold e e