Skip to content

Instantly share code, notes, and snippets.

There'd be a standard signature somewhere, which I will call Dist.DataFiles, and it'd look like this

module Dist.DataFiles(getDataFileName) where
  getDataFileName :: FilePath -> IO FilePath

This would have a handful of basic, built-in implementations, including the often-standard

@aisamanra
aisamanra / turing_morphogenesis.hs
Created August 19, 2016 18:43
A quick naïve Haskell implementation
import Control.Monad (forM_)
import Data.Array
import Data.Ix
import System.Random (randomIO)
-- A 'Size' is just a pair of Ints
type Pair = (Int, Int)
-- An 'Image' is a packed, pair-indexed array
type Image a = Array Pair a
@aisamanra
aisamanra / simple_hans_server.hs
Created June 1, 2016 06:09
A basic application written using ssh-hans
module Main where
{-
Here is a real---if not particularly interesting---interaction with this server:
[gdritter@armilla ~]$ ssh -p 9999 localhost incr
ok.
[gdritter@armilla ~]$ ssh -p 9999 localhost incr
ok.
[gdritter@armilla ~]$ ssh -p 9999 localhost double
#include <stdio.h>
typedef struct {
int tag;
union {
int l;
struct {
char* fst;
float snd;
} r;
main: libsample.a
gcc -lpthread -ldl main.c libsample.a -o main
libsample.a: sample.rs
rustc --crate-type=staticlib sample.rs
clean:
rm -f main libsample.a
/* This is a naive implementation of Jonathan McCabe's elaboration of
* Alan Turing's model of morphogenesis, as described here:
* http://www.jonathanmccabe.com/Cyclic_Symmetric_Multi-Scale_Turing_Patterns.pdf
*/
extern crate rand;
use rand::Rng;
use std::env;
use std::io::Write;
@aisamanra
aisamanra / untyped.rs
Last active April 10, 2018 23:45
Basic Rust implementation of an interpreter for the untyped lambda calculus
// A basic intepreter for the untyped lambda calculus
enum Term
{ Num(int)
, Var(~str)
, Lam(~str, ~Term)
, App(~Term, ~Term)
, Let(~str, ~Term, ~Term)
}
@aisamanra
aisamanra / jsonfs.hs
Created November 13, 2014 07:17
Quick-and-dirty program to mount JSON as a read-only file system
{-# LANGUAGE OverloadedStrings #-}
-- WARNING! This is very bad, quickly-written code, and should not be
-- trusted to do anything right! It does not support writing, and still
-- has several problems even for reading. Also it's ugly and bad.
import qualified Data.ByteString as BSS
import Data.ByteString.Lazy (ByteString)
import qualified Data.ByteString.Lazy as BS
import Data.Char (isDigit)
#[derive(Debug)]
enum Expr {
Var { x: u32 },
App { f: ExprRef, arg: ExprRef },
Lam { body: ExprRef },
}
use Expr::*;
#[derive(Debug, Copy, Clone)]
@aisamanra
aisamanra / Makefile
Created May 17, 2019 00:28
C++ module example
CPPFLAGS = -std=c++1z -fmodules-ts
ALL: main
main: speech.o main.cc
clang++ $(CPPFLAGS) -fprebuilt-module-path=. -o $@ $^
speech.o: speech.pcm
clang++ $(CPPFLAGS) -o $@ -c $<