Skip to content

Instantly share code, notes, and snippets.

View bens's full-sized avatar

Ben Sinclair bens

  • Sydney, Australia
  • 13:35 (UTC +10:00)
View GitHub Profile
@bens
bens / fold.ts
Last active September 7, 2020 01:14
Compositional folds in typescript
export default class Fold<A, B> {
private constructor(
private readonly state: any,
private readonly step: (x: A, st: any) => any,
private readonly done: (st: any) => B
) {}
public static of<A, B, S>(
state: S,
step: (x: A, st: S) => S,
@bens
bens / hellosdlgl31.zig
Created May 10, 2020 14:36
Hello World for OpenGL 3.3 with SDL2 in ziglang
const std = @import("std");
const Allocator = std.mem.Allocator;
const c = @cImport({
@cInclude("./gl_core_3_3.h");
@cInclude("SDL2/SDL.h");
@cInclude("SDL2/SDL_opengl.h");
});
const SDLError = error{
FailedInit,
@bens
bens / hellosdl.zig
Last active April 26, 2020 15:23
Hello World for SDL2 in ziglang
const std = @import("std");
const c = @cImport(@cInclude("SDL2/SDL.h"));
const SDLError = error{
FailedInit,
FailedCreatingWindow,
FailedGettingEvent,
FailedDraw,
FailedScreenUpdate,
};
@bens
bens / debruijn.maude
Last active August 8, 2019 04:08
Untyped Lambda Calculus with de Bruijn indices in Maude
fmod LAMBDA is pr NAT . pr QID .
*** User-level lambda expressions, using named binders.
sorts Expr EName .
subsort Nat EName < Expr .
subsort Qid < EName .
op __ : Expr Expr -> Expr [ctor] .
op [\_._] : EName Expr -> Expr [ctor] .
op let_:=_in_ : EName Expr Expr -> Expr .
eq let X := A in B = [\ X . B ] A .
@bens
bens / filter.agda
Last active May 24, 2019 12:14
map then filter on vectors and lists
module filter where
open import Data.Bool using (Bool; true; false)
open import Data.List using (List; []; _∷_)
open import Data.Nat using (ℕ; suc; _≤_; z≤n; s≤s; _≟_)
open import Data.Nat.Properties using (≤-trans)
open import Data.Nat.Show using (show)
open import Data.Product using (Σ-syntax; _×_; _,_)
open import Data.String using (String)
open import Data.Vec using (Vec; []; _∷_)
@bens
bens / ddc-make-war.txt
Created March 17, 2018 02:16
DDC make war ouptut
make/config.mk:
---
DDC_FLOW_USE_LINEAR_SOLVER = 1
=================================================================================================================
$ make war
...
(181.0/380) test/ddc-regress/core/04-Flow/80-Rate/30-Map2/Test.dcx std run success (138.3ms)
-- Output Differs -------------------------------------------------------------
expected file: test/ddc-regress/core/04-Flow/80-Rate/30-Map2/Test.stdout.check
@bens
bens / stlc-infer.curry
Last active July 25, 2017 11:48
Simple Type Inference in Curry
module typecheck where
data Type = Int | Type ==> Type
data AST
= Lit Int
| Var Type String
| App Type AST AST
| Lam Type String AST
@bens
bens / AllTests.hs
Created February 12, 2017 00:00
Tests for concurrent-machines
module Main (main) where
import Control.Concurrent (threadDelay)
import Control.Exception (catch, throwIO)
import Control.Monad (when, forM_)
import Control.Monad.IO.Class (MonadIO, liftIO)
import Control.Monad.Trans.Writer
import Control.Monad.Trans.Class (lift)
import Data.Machine.Concurrent
import Data.Time.Clock (UTCTime, addUTCTime, diffUTCTime, getCurrentTime)
@bens
bens / diceroller.hs
Last active August 20, 2019 00:16
Dice Roller
module Main (main) where
import Control.Applicative (optional)
import Control.Monad (replicateM)
import Control.Monad.Trans.State (State, runState, state)
import Data.List (sortOn)
import Data.Maybe (isJust)
import Data.Ord (Down(Down))
import System.Environment (getArgs)
import System.Random (RandomGen, getStdGen, randomR, setStdGen)
@bens
bens / free.hs
Created December 21, 2015 23:31
Retaining parallel semantics in a free monad
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE ExistentialQuantification #-}
import Data.Semigroup
example :: Validation [String] Int Int
example = do
x <- (+) <$> validation ["not even"] even
<*> validation ["not positive"] (0 <)
y <- validation ["not divisible by four"] (\a -> a `mod` 4 == 0)