Skip to content

Instantly share code, notes, and snippets.

View bens's full-sized avatar

Ben Sinclair bens

  • Sydney, Australia
  • 05:28 (UTC +10:00)
View GitHub Profile
import Control.Monad.Trans.State.Strict
import Control.Monad.Trans.Class
import Test.Tasty (TestTree, defaultMain, testGroup)
import Test.Tasty.QuickCheck (testProperty)
import Test.QuickCheck
import Data.Machine
import Data.Machine.Fanout
import Data.Machine.Lift
@bens
bens / Benchmarks.hs
Created December 5, 2015 12:33
Benchmarking Data.Machine.Fanout implementations
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
import qualified Data.Machine.Fanout as BenS
@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)
@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 / 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 / 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 / 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 / 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 / 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 / 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,
};