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 str = System.IO.File.ReadAllText "C:\\Users\\Jon\\Documents\\pg10.txt" | |
let re = System.IO.File.ReadAllText "C:\\Users\\Jon\\Documents\\re.txt" | |
for _ in 1..3 do | |
let timer = System.Diagnostics.Stopwatch.StartNew() | |
let re = Regex(re, RegexOptions.Compiled) | |
let res = Array.Parallel.init 4 (fun _ -> re.Split str |> Seq.sumBy (fun m -> m.Length)) | |
printfn "%A %fs" res timer.Elapsed.TotalSeconds |
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
[<CompilationRepresentation(CompilationRepresentationFlags.UseNullAsTrueValue)>] | |
type Tree = Empty | Node of Tree * Tree | |
let rec make depth = | |
if depth=0 then Empty else Node(make (depth-1), make (depth-1)) | |
let rec check = function | |
| Empty -> 1 | |
| Node(l, r) -> 1 + check l + check r |
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 <algorithm> | |
#include <iostream> | |
#include <chrono> | |
struct Node { | |
Node *l, *r; | |
Node() : l(0), r(0) {} | |
Node(Node* l2, Node* r2) : l(l2), r(r2) {} | |
~Node() { delete l; delete r; } | |
int check() const { |
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
; 20LOC to define a useful language | |
; However, no strings, IO, closure semantics or GC. | |
apply[fn;x;a] = | |
[atom[fn] -> [eq[fn;CAR] -> caar[x]; | |
eq[fn;CDR] -> cdar[x]; | |
eq[fn;CONS] -> cons[car[x];cadr[x]]; | |
eq[fn;ATOM] -> atom[car[x]]; | |
eq[fn;EQ] -> eq[car[x];cadr[x]]; | |
T -> apply[eval[fn;a];x;a]]; |
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 benchmark maintains an array of roots and randomly either pushes | |
onto them and relinks them or empties them. If I designed it correctly | |
then this should rapidly create unreachable subgraphs, some of which | |
are cyclic. | |
This is a torture test for any kind of reference counting. | |
*) | |
type Vertex = { mutable Dst: Vertex } |
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
(* | |
The resizable array xs is required for the first half of the execution of | |
this "test" function but not the last half. Collecting xs as early as possible | |
would mean collecting it halfway through the execution of "test" but this | |
is practically impossible. Doing so in general is equivalent to solving the | |
halting problem. | |
*) | |
let next n = | |
6364136223846793005UL*n + 1442695040888963407UL |
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
type Json = | |
| Null | |
| Bool of bool | |
| Number of float | |
| String of string | |
| Array of Json list | |
| Object of (string * Json) list | |
type Bracket = Open | Close |
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
// Translated from the Ray Tracer Language Comparison | |
// http://www.ffconsultancy.com/languages/ray_tracer/benchmark.html | |
import Printf | |
struct Hit | |
l ::Float64 | |
d ::Array{Float64, 1} | |
end |
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
// The famous fast inverse square root approximation from | |
// Quake ported to F#. | |
// Note: this algorithm is not fast on modern computers | |
// and this implementation of it is extremely inefficient: | |
// for educational purposes only! | |
open System | |
let isqrt y = | |
let x2 = y * 0.5f |
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 reint = R(Regex "[0-9]+") | |
let relident = R(Regex "[a-z][a-zA-Z0-9]*") | |
let grammar : Grammar<Entry> = | |
[ | |
Expr, | |
[ [ S"if"; C Expr; S"then"; C Expr; S"else"; C Expr ], fun [E p; E t; E f] -> E(If(p, t, f)) | |
[ C Expr; S"<="; C Expr ], fun [E e1; E e2] -> E(BinOp(e1, Le, e2)) | |
[ C Expr; S"+"; C Expr ], fun [E e1; E e2] -> E(BinOp(e1, Add, e2)) | |
[ C Expr; S"-"; C Expr ], fun [E e1; E e2] -> E(BinOp(e1, Sub, e2)) |