Skip to content

Instantly share code, notes, and snippets.

View eiriktsarpalis's full-sized avatar
🌴
On vacation

Eirik Tsarpalis eiriktsarpalis

🌴
On vacation
View GitHub Profile
@eiriktsarpalis
eiriktsarpalis / fsharp-listings.tex
Created August 13, 2013 19:10
LaTeX F# definition for Listings package
\usepackage{listings}
\usepackage{upquote}
\lstdefinelanguage{FSharp}%
{morekeywords={let, new, match, with, rec, open, module, namespace, type, of, member, %
and, for, while, true, false, in, do, begin, end, fun, function, return, yield, try, %
mutable, if, then, else, cloud, async, static, use, abstract, interface, inherit, finally },
otherkeywords={ let!, return!, do!, yield!, use!, var, from, select, where, order, by },
keywordstyle=\color{bluekeywords},
sensitive=true,
@eiriktsarpalis
eiriktsarpalis / cont.fsx
Last active December 22, 2020 00:32
A Continuation monad with stacktrace support in F# 4.1
open System
open System.Runtime.CompilerServices
type SymbolicException =
{
Source : Exception
Stacktrace : string list
}
module SymbolicException =
@eiriktsarpalis
eiriktsarpalis / PriorityQueue.cs
Last active September 22, 2020 17:34 — forked from safern/PriorityQueue.cs
PriorityQueue api surface
namespace System.Collections.Generic
{
class PriorityQueue<TElement, TPriority> : IReadOnlyCollection<(TElement Element, TPriority Priority)>
{
#region Constructors
public PriorityQueue() { }
public PriorityQueue(IComparer<TPriority> comparer) { }
public PriorityQueue(IEnumerable<(TElement Element, TPriority Priority)> values) { }
public PriorityQueue(IEnumerable<(TElement Element, TPriority Priority)> values, IComparer<TPriority> comparer) { }
#endregion
@eiriktsarpalis
eiriktsarpalis / for-cancellation.fsx
Created October 26, 2017 12:01
Encoding Cancellation on top of foreach loops
// One of the common annoyances when writing imperative code in F# is that the
// expression-based nature of the language makes it effectively impossible to
// break or return in the midst of a for-loop. This is an attempt to encode
// lightweight cancellation on top of native for loops. As usual, this is intended
// as a PoC and should not be considered seriously for production code.
module Seq =
open System.Collections
open System.Collections.Generic
@eiriktsarpalis
eiriktsarpalis / Atom.cs
Created June 22, 2019 12:20
Clojure-style atoms for C#
using System;
using System.Threading;
using System.Threading.Tasks;
namespace Atom
{
public class Atom<T> where T : class
{
private T _value;
@eiriktsarpalis
eiriktsarpalis / ThunkBuilder.cs
Last active April 6, 2020 10:26
Delayable MethodBuilders
using System;
using System.Collections.Concurrent;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.ExceptionServices;
using System.Security;
using System.Threading.Tasks;
namespace ThunkBuilder
{
@eiriktsarpalis
eiriktsarpalis / Maybe.cs
Last active April 6, 2020 10:26
Encoding a Maybe monad in C# using Eff, https://github.com/nessos/Eff
namespace Maybe
{
public struct Maybe<T>
{
public bool HasValue { get; }
public T Value { get; }
private Maybe(T value)
{
HasValue = true;
@eiriktsarpalis
eiriktsarpalis / Results.md
Last active February 5, 2020 16:53
ObjectIdGenerator Performance
Method N Mean Error StdDev Gen 0 Gen 1 Gen 2 Allocated
ObjectIdGenerator 10 261.0 ns 3.92 ns 3.28 ns 0.0176 - - 280 B
DictObjectIdGenerator 10 415.4 ns 7.92 ns 8.81 ns 0.0167 - - 264 B
ObjectIdGenerator 100 2,237.4 ns 38.87 ns 32.45 ns 0.0458 - - 776 B
DictObjectIdGenerator 100 3,697.2 ns 72.95 ns 71.64 ns 0.0648 - - 1040 B
ObjectIdGenerator 1000 27,641.9 ns 465.12 ns 412.32 ns 0.0916 - - 1912 B
DictObjectIdGenerator 1000 35,959.2 ns
@eiriktsarpalis
eiriktsarpalis / ackermann.cs
Created November 19, 2019 12:48
Task vs ValueTask performance
using System;
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
namespace ValueTaskBenchmarks
{
// Uses the Ackermann function to measure performance of task and friends
// c.f. https://en.wikipedia.org/wiki/Ackermann_function
@eiriktsarpalis
eiriktsarpalis / slnTools.fsx
Created December 17, 2018 13:40
Solution Generation
[<RequireQualifiedAccess>]
module SlnTools
// Simple tool for generating Solution files out of a list of projects.
open System
open System.IO
open System.Text.RegularExpressions
let fsharpProjectTypeGuid = Guid.Parse "6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705"