Skip to content

Instantly share code, notes, and snippets.

ekmett / monads for plt-racket
Created Jun 26, 2010
Monads for PLT Racket
View monads for plt-racket
(module monad scheme
(require "")
;; i'm too lazy to repeat this pattern for now.
(define-syntax init-public
(syntax-rules ()
((_) (begin))
((_ (m default) ms ...) (begin
(init-field (m default))
(public (internal-m m))
(define (internal-m . rest) (apply (get-field m this) rest))
pjlsergeant / gist:1803656
Created Feb 11, 2012
Game of Life in 131 characters of Perl.
View gist:1803656
use strict;
# Accepts a grid size, and a list representing the grid. 131
my $result = join '', $life->( 5, qw/
rsimoes /
Created Feb 22, 2012
Long-winded linearly typed variables
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Dump;
use Data::Alias "alias";
use Scalar::Util qw(weaken isweak);
my $foo = ["a".."z"];
alias my @bar = @$foo;
View factor.hs
npto :: (Integral a) => a -> [a]
npto x = [2,3] ++ concat [[x*6-1,x*6+1] | x <- [1..n]]
where n = ((+1) . round . sqrt . fromIntegral $ x) `div` 6
factors :: (Integral a) => a -> [a]
factors 1 = []
factors x = least : factors (x `div` least)
where least = head $ fs ++ [x]
fs = filter ((==0) . mod x) . npto $ x
timjb / cloud-haskell-operational-transformation.hs
Created Oct 14, 2012
Simulation of Operational Transformation with Cloud Haskell
View cloud-haskell-operational-transformation.hs
This is a simple simulation of OT with Cloud in which all slaves generate
and apply random operations. It should work in theory. In practice, however
I wasn't apply to test it because my installation of distributed-process is
apparently broken. Specifically, `spawn` doesn't seem to work (I tested it
with some examples from the Well-Typed blog).
This code depends on
Fuuzetsu / hackagedocs
Last active Apr 9, 2016
Script for generating and uploading missing documentation for your Hackage packages. Now with fixed package links and contents page.
View hackagedocs
#!/usr/bin/env bash
cabal configure && cabal build && cabal haddock --hyperlink-source \
--html-location='/package/$pkg-$version/docs' \
if [ "${S}" -eq "0" ]; then
cd "dist/doc/html"
cp -r "${1}" "${DDIR}" && tar -c -v -z --format=ustar -f "${DDIR}.tar.gz" "${DDIR}"
twanvl / machinesbench.hs
Created Jun 7, 2016
Machines benchmark modified to include vector stream fusion. Addapted from, which is in turn based on
View machinesbench.hs
{-#LANGUAGE NoMonomorphismRestriction #-}
module Main (main) where
import Control.Monad (void)
import Control.Monad.Identity
import Criterion.Main
import qualified Data.Conduit as C
import qualified Data.Conduit.Combinators as CC
import qualified Data.Conduit.List as C
import qualified Data.Machine as M
tonyg / monad.rkt
Last active Sep 9, 2016
Monads in Racket
View monad.rkt
#lang racket/base
;; Monads in Racket, including polymorphic bind, return and fail.
;; Haskell-like do-notation.
(provide define-monad-class
(struct-out monad-class)
View index.html
<!DOCTYPE html>
<title>Large Type</title>
<link rel="stylesheet/less" type="text/css" href="style.less">
<script type="text/javascript" src="lib/jquery-2.1.4.min.js"></script>
<script type="text/javascript" src="lib/less.min.js"></script>
<div class="out"><span contenteditable autofocus>*hello*</span></div>
yelouafi / delimited-continuations.js
Last active Jun 25, 2020
delimited continuations using javascript generators
View delimited-continuations.js
// We model the call stack using a linked list of Generators
// Each Generator has a _return field pointing back to its parent
function stepGen(gen, arg) {
const {done, value} =
if(done) {
if(gen._return) {
stepGen(gen._return, value)