Skip to content

Instantly share code, notes, and snippets.

View ListBuilding.fs
open System
open System.Buffers
open System.Collections.Generic
open BenchmarkDotNet.Running
open BenchmarkDotNet.Attributes
[<Struct>]
type Entry =
{
I : int
View SliceSet2D.fsx
type All = All
type SliceIndex2D<'a, 'b when 'a : equality and 'b : equality>(values: seq<'a * 'b>) =
let values = Array.ofSeq values
member s.Item
with get (k1: 'a, _: All) =
values
|> Seq.filter (fun (a, _) -> a = k1)
View NewLangThoughts.md

Tractor: A CLR Language for Numerical Computation

The original intention of the dotnet was to provide a runtime for many programming languages to run on. Two factors have kept that vision from fruition: tying .NET Framework to Windows and the dominance of C#.

Dotnet can now run on almost any modern system. A significant push has been made toward performance features for C# and the CLR. The intention is to close the performance gap between systems-level programming languages (C, C++, Rust, Zig, and Odin, to name a few) and what can be achieved on the dotnet platform.

A general-purpose language like C# and F# must support

Guiding Principles

View settings.json
{
"workbench.colorTheme": "GDScript",
"editor.tokenColorCustomizations": {
"[Dracula Soft]": {
"textMateRules": [
{
"scope": "keyword.fsharp",
"settings": {
"foreground": "#65d6ff8b",
}
View BitSet Iteration
open System
open System.Collections
open System.Collections.Generic
module private Helpers =
let inline computeBucketAndMask (itemKey: int<'Item>) itemCount =
if (uint itemKey) >= (uint itemCount) then
raise (IndexOutOfRangeException (nameof itemKey))
View StackStack.fsx
[<Struct;IsByRefLike>]
type StackStack<'T>(values: Span<'T>) =
[<DefaultValue>] val mutable private Count : int
member s.Push v =
if s.Count < values.Length then
values[s.Count] <- v
s.Count <- s.Count + 1
else
failwith "Exceeded capacity of StackStack"
@matthewcrews
matthewcrews / PrivateUoM.fsx
Created Apr 30, 2022
Define a UoM which can only be created from a "constructor"
View PrivateUoM.fsx
module Units =
[<Measure>] type private Chicken
module Chicken =
let create x =
if x < 0 then
invalidArg (nameof x) "Cannot have a Chicken <0"
View FastVsSlow.fs
open System
open BenchmarkDotNet.Attributes
open BenchmarkDotNet.Running
open BenchmarkDotNet.Diagnosers
[<HardwareCounters(HardwareCounter.BranchMispredictions, HardwareCounter.CacheMisses)>]
[<DisassemblyDiagnoser(printSource = true, exportHtml = true)>]
type Benchmarks () =
let rng = Random 123
View Program.Benchmarks-20220214-133917.log
// Validating benchmarks:
// ***** BenchmarkRunner: Start *****
// ***** Found 2 benchmark(s) in total *****
// ***** Building 1 exe(s) in Parallel: Start *****
// start dotnet restore /p:UseSharedCompilation=false /p:BuildInParallel=false /m:1 /p:Deterministic=true /p:Optimize=true in C:\Users\matth\source\repos\TypedArrayIndexing\bin\Release\net6.0\af583c40-01ab-4113-bd10-b7f8ac106bac
// command took 1s and exited with 0
// start dotnet build -c Release --no-restore /p:UseSharedCompilation=false /p:BuildInParallel=false /m:1 /p:Deterministic=true /p:Optimize=true in C:\Users\matth\source\repos\TypedArrayIndexing\bin\Release\net6.0\af583c40-01ab-4113-bd10-b7f8ac106bac
// command took 0.9s and exited with 1
// start dotnet build -c Release --no-restore --no-dependencies /p:UseSharedCompilation=false /p:BuildInParallel=false /m:1 /p:Deterministic=true /p:Optimize=true in C:\Users\matth\source\repos\TypedArrayIndexing\bin\Release\net6.0\af583c40-01ab-4113-bd10-b7f8ac106bac
// command took 1.62s and exite
View UoM Slicing.fsx
[<Measure>] type Chicken
[<Measure>] type Cow
type Arr<[<Measure>] 'Measure>(v: array<_>) =
let values = v
member _.Item
with inline get (i: int<'Measure>) =
v.[int i]