Skip to content

Instantly share code, notes, and snippets.

Gatlin Johnson gatlin

Block or report user

Report or block gatlin

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
gatlin / adt.rkt
Created Feb 18, 2014
Playing with ADTs and other bullshit
View adt.rkt
#lang racket
; simple cons pairs
(define (my-cons fst snd)
(λ (f) (f fst snd)))
(define (my-first c)
(c (λ (a b) a)))
(define (my-second c)
gatlin / booldef.rkt
Last active Aug 29, 2015
Languages don't need built-in conditionals! Bah!
View booldef.rkt
(define True (λ () (λ (a b) (a))))
(define False (λ () (λ (a b) (b))))
gatlin / simple_alarm.hs
Created Apr 15, 2014
Load this into ghci, load a song into your MPD playlist, and then run startTimer with the correct number of seconds.
View simple_alarm.hs
{-# LANGUAGE OverloadedStrings #-}
import Network.MPD
import Control.Concurrent.Timer
import Control.Concurrent.Suspend.Lifted
import System.Environment
startTimer seconds = oneShotTimer (withMPD (play Nothing) >> return ()) (sDelay (fromInteger seconds))
gatlin /
Last active Aug 29, 2015
Tail recursive, algebraic definition of a simple cons list in Python, along with some example functions.
def tail_rec(fun):
Receive a function `fun` as an argument;
Return a function which accepts `fun` and runs it in a loop.
def tail(fun):
a = fun
while callable(a):
a = a()
return a
gatlin / fizzbuzz.hs
Last active Aug 29, 2015
Haskell FizzBuzz solution using monoids. I didn't write this but I wanted to separate it from its original article for didactic reasons.
View fizzbuzz.hs
{-# LANGUAGE MonadComprehensions #-}
-- From
import Data.Monoid ((<>))
import Data.Maybe (fromMaybe)
import Control.Monad (mapM_)
fizzbuzz x = fromMaybe (show x) $ [ "fizz" | x `rem` 3 == 0 ]
<> [ "buzz" | x `rem` 5 == 0 ]
gatlin / free_monad_functor_adt.hs
Created Jun 10, 2014
Two things in one: functors implemented as algebraic data types; and a free monad derived automatically from it. No typeclasses necessary!
View free_monad_functor_adt.hs
{-# LANGUAGE RankNTypes #-}
data F f = F {
_map :: forall a b. (a -> b) -> f a -> f b
data Mu f a
= Term { retract :: a }
| Cont (f (Mu f a))
gatlin / freestream.hs
Last active Aug 29, 2015
Iteratee-based Streaming utilities from a free monad
View freestream.hs
gatlin / typeops.lhs
Created Jul 25, 2014
Type operators
View typeops.lhs
Type operators!
Turns out a GHC language extension makes a lot of cool things possible that I
think you hinted at:
> {-# LANGUAGE TypeOperators #-}
> data a + b = Inl a | Inr b deriving Show
gatlin / id.js
Created Aug 8, 2014
Example of using closures in JavaScript to create a protected generator
View id.js
var getId = function() {
var _id = 0;
return function() {
return _id++;
// usage
View closurewanking.js
* Fun with closures!
* Run this with node.js:
* $> node closurewanking.js
var http = require('http');
You can’t perform that action at this time.