Skip to content

Instantly share code, notes, and snippets.

View sleexyz's full-sized avatar

Sean Lee sleexyz

View GitHub Profile
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
-- 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)
{-# LANGUAGE RecordWildCards #-}
data Person = Person {name :: String, address :: String}
me = Person {name = "Sean", address = "315 Seigel St"}
foo :: String
foo =
let Person{..} = me
in
@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 NoMonomorphismRestriction #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables #-}
module DiagramsTidal where
import Sound.Tidal.Pattern hiding (square)
import Sound.Tidal.Time
import Sound.Tidal.Utils
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
signature MONOID =
sig
type t
val append : t * t -> t
val zero : t
end
structure Additive =
struct
type t = int
http://comonad.com/reader/2008/representing-adjunctions/
Let Hask be Set?
SET:
Objects are sets
Morphisms are total functions between sets
(wait, Hom-Sets are exponentials?????)
HASK:
@sleexyz
sleexyz / findwithdefault.hs
Last active August 30, 2016 17:01
hylogen 1.4
import Hylogen.Expr
import Hylogen.WithHylide
findWithDefault :: ToGLSLType a =>
(Expr a -> Booly) -> Expr a -> [Expr a] -> Expr a
findWithDefault predicate = foldr (\x acc -> sel (predicate x) x acc)
findWithDefault' :: (ToGLSLType a, ToGLSLType b) =>
(Expr a -> Booly) -> Expr b -> [(Expr a, Expr b)] -> Expr b
{-# LANGUAGE RecordWildCards #-}
data Foo = Bar { a :: Int, b :: Int, c :: Int, d :: Int }
| Baz { x :: Int, y :: Int, z :: Int, w :: Int }
deriving (Show)
bar = Bar {a=1, b=2, c=3, d=4}
baz = Baz {x=10, y=20, z=30, w=40}