Skip to content

Instantly share code, notes, and snippets.

@mrange
mrange / FsTranducers.fs
Created Apr 25, 2019
F# Transducers test
View FsTranducers.fs
module Common =
let inline adapt f = OptimizedClosures.FSharpFunc<_, _, _>.Adapt f
let inline invoke f s v = (f : OptimizedClosures.FSharpFunc<_, _, _>).Invoke (s, v)
module MinimalisticTransducers =
// Disable Tiered compilation using powershell: $env:COMPlus_TieredCompilation=0
let inline (^>) l r = l r
let inline (>->) l r v = l (r v)
@mrange
mrange / README.md
Last active Apr 23, 2019
[F#/OCaml] Implementing a data streams library using a bunch of one-liners
View README.md

[F#/OCaml] Implementing a data streams library using a bunch of one-liners

A few years ago when I read the presentation motivating the design behind Nessos Streams I was struck by the beauty of simplistic push streams.

type PushStream<'T> = ('T -> bool) -> bool

LINQ (in .NET) is a pull stream, ie we pull values out of the stream by calling MoveNext + Current. One of the problems with pull streams is the constant checking "Are we done?" at each level in the stream.

@mrange
mrange / README.md
Created Apr 22, 2019
The perceived simplPush Streams
View README.md

Implementing a functional data streams library using a bunch of one-liners

A few years ago when I read the presentation motivating the design behind Nessos Streams I was struck by the beauty of simplistic push streams.

type PushStream<'T> = ('T -> bool) -> bool

LINQ is a pull stream, ie we pull values out of the stream by calling MoveNext + Current. One of the problems with pull streams is the constant checking "Are we done?" at each level in the stream.

@mrange
mrange / 0_PushStream.fs
Last active Apr 20, 2019
Minimalistic Streams
View 0_PushStream.fs
module PushStreams =
let flip f l r = f r l
let pushIf f r v = if f v then r v else true
let empty r = true
let singleton v r = r v
let collect c s r = flip c r |> s
let map m s r = m >> r |> s
let filter f s r = pushIf f r |> s
let rec ofList vs r =
@mrange
mrange / message_processor.cpp
Last active Apr 14, 2019
message processor C++
View message_processor.cpp
#include <cassert>
#include <condition_variable>
#include <deque>
#include <iostream>
#include <functional>
#include <memory>
#include <mutex>
#include <string>
#include <thread>
View impulse_box.glsl
#version 150
in VertexData
{
vec4 v_position;
vec3 v_normal;
vec2 v_texcoord;
} inData;
out vec4 fragColor;
@mrange
mrange / impulse.glsl
Last active Apr 11, 2019
Impulse invite 2019
View impulse.glsl
// License Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
// A "retro" invitation created for my old Atari ST buddies for a
// summer get-together. I wanted the Atari ST demo feeling with
// chiptune music (soundcloud is sometimes struggling to load)
// and unpolished and a bit too colorful screens.
// Of course, it all needs to end with an impossible to read
// scrolltext. It's just how it was supposed to work on the
// old Atari ST :)
View clouds.glsl
#version 150
in VertexData
{
vec4 v_position;
vec3 v_normal;
vec2 v_texcoord;
} inData;
out vec4 fragColor;
@mrange
mrange / fstest.fs
Last active Mar 24, 2019
functional test
View fstest.fs
module FsTest =
type TestContext = TC of string list
[<RequireQualifiedAccess>]
type TestFailure =
| Exception of exn
| Assertion of string
[<RequireQualifiedAccess>]
type TestFailureTree =
@mrange
mrange / avx_raymarch.fs
Last active Mar 19, 2019
Raymarcher in F#
View avx_raymarch.fs
#nowarn "9"
open System
open System.Diagnostics
open System.Numerics
open SixLabors.ImageSharp
open SixLabors.ImageSharp.Processing
open SixLabors.ImageSharp.PixelFormats
open SixLabors.ImageSharp.Advanced
open System.Threading.Tasks
You can’t perform that action at this time.