Skip to content

Instantly share code, notes, and snippets.

@Hirrolot
Hirrolot / a-preface.md
Last active April 18, 2024 16:50
A complete implementation of the positive supercompiler from "A Roadmap to Metacomputation by Supercompilation" by Gluck & Sorensen

Supercompilation is a deep program transformation technique due to V. F. Turchin, a prominent computer scientist, cybernetician, physicist, and Soviet dissident. He described the concept as follows [^supercompiler-concept]:

A supercompiler is a program transformer of a certain type. The usual way of thinking about program transformation is in terms of some set of rules which preserve the functional meaning of the program, and a step-by-step application of these rules to the initial program. ... The concept of a supercompiler is a product of cybernetic thinking. A program is seen as a machine. To make sense of it, one must observe its operation. So a supercompiler does not transform the program by steps; it controls and observes (SUPERvises) the running of the machine that is represented by the program; let us call this machine M1. In observing the operation of

@badamczewski
badamczewski / Morph.cs
Created December 1, 2020 14:11
Text Morphing in WPF
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Animation;
namespace WPFAnimations
@jhewlett
jhewlett / new-fsharp-kata.sh
Created April 8, 2019 03:39
Template for F# Coding Exercies (simple class library and test project)
mkdir Kata
cd Kata
dotnet new sln
mkdir App
cd App
dotnet new classlib -lang F#
@jdh30
jdh30 / MicroKanren.fs
Created February 18, 2017 15:26
MicroKanren ported from Scheme to F#
type Term =
| Var of int
| Pair of Term * Term
| Int of int
let (|Find|_|) s k = Map.tryFind k s
let rec walk (s: Map<_,_>) = function
| Var(Find s t) -> walk s t
| t -> t
@jwosty
jwosty / StateBuilder.fsx
Created March 24, 2016 23:44
F# state monad / computation expression builder, and example usage
open System
open System.IO
type State<'s, 'a> = State of ('s -> ('a * 's))
module State =
let inline run state x = let (State(f)) = x in f state
let get = State(fun s -> s, s)
let put newState = State(fun _ -> (), newState)
let map f s = State(fun (state: 's) ->
@riyadparvez
riyadparvez / StreamTokenizer.cs
Last active February 6, 2024 07:40
C# port of java's StreamTokenizer class. Everything kept same except some renaming for following C# naming convention. And it also implements IEnumerable for foreach support
/**
* The <code>StreamTokenizer</code> class takes an input stream and
* parses it into "tokens", allowing the tokens to be
* Read one at a time. The parsing process is controlled by a table
* and a number of flags that can be set to various states. The
* stream tokenizer can recognize identifiers, numbers, quoted
* strings, and various comment styles.
* <p>
* Each byte Read from the input stream is regarded as a character
* in the range <code>'&#92;u0000'</code> through <code>'&#92;u00FF'</code>.
open System
type Cont<'T> =
abstract Call<'R> : ('T -> 'R) * (exn -> 'R) -> 'R
let protect f x cont econt =
let res = try Choice1Of2 (f x) with err -> Choice2Of2 err
match res with
| Choice1Of2 v -> cont v
| Choice2Of2 v -> econt v