This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let primes = | |
[|3; 7; 13; 31; 61; 127; 251; 509; 1021; 2039; 4093; 8191; 16381; 32749; | |
65521; 131071; 262139; 524287; 1048573; 2097143; 4194301; 8388593; | |
16777213; 33554393; 67108859; 134217689; 268435399; 536870909; 1073741789; | |
2147483647|] | |
let mods = | |
[|(fun n -> n mod 3); | |
(fun n -> n mod 7); | |
(fun n -> n mod 13); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Upload files from this machine to another without clobbering. | |
# Usage: | |
# ./upload.sh <srcdir> <user@host> <dstdir> | |
tar -cz $1 | ssh $2 "tar -kzxf - -C ${3}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System.Threading | |
/// Spawn a new Task. | |
let task f x = | |
Tasks.Task<_>.Factory.StartNew(fun () -> f x) | |
module internal Internal = | |
/// Compute "map f [i0, i2) |> reduce g" in parallel using divide and conquer. | |
/// Assumes "f" is associative but does not assume that it is commutative. | |
/// Therefore, this function can return "f (f 0 1) (f 2 3)" but not "f 1 0" etc. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System.Text.RegularExpressions | |
let alphabet = ['a'..'z'] | |
let edits1 (w: string) = | |
seq { for i in 0 .. w.Length do | |
if i < w.Length then | |
yield w.[0..i-1] + w.[i+1..] // Delete | |
if i < w.Length-1 then | |
yield w.[0..i-1] + w.[i+1..i+1] + w.[i..i] + w.[i+2..] // Swap |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
This tiny 211-line compiler converts programs written in a little ML dialect into 32-bit ARM | |
assembly. | |
This program is most easily run using FSI with flags to turn off FSI's output so the output | |
of this program can be piped into a file: | |
dotnet fsi --quiet --exec compiler7.fs >fib.s | |
That file can then be compiled with: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let mutable globalException : System.Exception = null // Compiler generated | |
let myGlobal = | |
if isNull globalException then // Compiler generated | |
try // Compiler generated | |
System.IO.File.ReadAllText "DoesNotExist.txt" | |
with e -> // Compiler generated | |
globalException <- e // Compiler generated | |
Unchecked.defaultof<_> // Compiler generated | |
else Unchecked.defaultof<_> // Compiler generated |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open System.Windows | |
let goldenRatio = (1.0 + sqrt 5.0) / 2.0 | |
let newBrush = | |
let mutable hue = 0.0 | |
fun () -> | |
hue <- hue + System.Math.PI / goldenRatio | |
let s x = byte(255.0 * x) | |
let c x = 0.5 * (cos x + 1.0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
do | |
use listener = new System.Net.HttpListener() | |
listener.Prefixes.Add "http://localhost:8080/" | |
listener.Start() | |
while true do | |
let context = listener.GetContext() | |
async { use input = context.Request.InputStream | |
use output = context.Response.OutputStream | |
input.CopyTo output } | |
|> Async.Start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// async_tcp_echo_server.cpp | |
// ~~~~~~~~~~~~~~~~~~~~~~~~~ | |
// | |
// Copyright (c) 2003-2012 Christopher M. Kohlhoff (chris at kohlhoff dot com) | |
// | |
// Distributed under the Boost Software License, Version 1.0. (See accompanying | |
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "stdafx.h" | |
#include <windows.h> | |
#include <regex> | |
#include <vector> | |
#include <string> | |
#include <fstream> | |
#include <cstdio> | |
#include <codecvt> |