Skip to content

Instantly share code, notes, and snippets.

View mwolicki's full-sized avatar

Marcin Wolicki mwolicki

View GitHub Profile
module Tree = struct
type z = Z : z
type 'a s = S : 'a s
type (_,_,_) max =
| MaxEq : 'a -> ('a,'a,'a) max
| MaxSuc : ('a, 'b, 'a) max -> ('a s, 'b, 'a s) max
| MaxFlip : ('a, 'b, 'c) max -> ('b, 'a, 'c) max
#if !INTERACTIVE
module Program
#endif
open BenchmarkDotNet.Diagnostics.Windows
open BenchmarkDotNet.Attributes
open BenchmarkDotNet
open BenchmarkDotNet.Running
open Hyperion.ValueSerializers
open System.Collections.Generic
open System
type Notifications<'key, 'item> =
| Add of addKey : 'key * addItem : 'item
| Update of updateKey : 'key * updateItem : 'item
| Remove of removeKey : 'key
| RemoveAll
type ISupervisedMailboxProcessor =
abstract Restart : unit -> unit
abstract AddChild : ISupervisedMailboxProcessor -> unit
type 'a Message =
| Message of 'a
| Restart
| AddActor of ISupervisedMailboxProcessor
exception RestartException
type Op =
| Add of (Op * Op)
| Mul of (Op * Op)
| Divide of (Op * Op)
| Substract of (Op * Op)
| Value of int
let mul a b = Mul (a, b)
let sub a b = Substract (a, b)
let v = Value
type Value =
| VInt of int
| VStr of string
type Id = Id of string
type Filter =
| All of Filter list
| Any of Filter list
open System.Threading
open System.Collections.Concurrent
type ThreadPool () =
let jobs = System.Collections.Concurrent.ConcurrentQueue<unit->unit> ()
let semaphore = new Semaphore (0, System.Int32.MaxValue)
let threads = ConcurrentBag<Thread>()
let postJob job =
jobs.Enqueue job
semaphore.Release () |> ignore
using System;
public static class Sort {
public static void quicksort(Span<int> arr){
void swap(Span<int> s, int i, int j){
var tmp = s[i];
s[i] = s[j];
s[j] = tmp;
}
int partition(Span<int> s) {
type Char = uint8
type Code = uint32
let compress (init_map : Map<Char list, Code>) (text:string) : Code list option=
let rec compress acc (text:Char list) maybeCode (map:Map<_,_>) : Code list option=
match text with
| c::cs ->
let currCode = c::acc
match map.TryFind currCode with
| Some code_for_current_key -> compress currCode cs (Some code_for_current_key) map
using System;
namespace FizzBuzz
{
class Program
{
static void Main(string[] args)
{
for(int i=1;i<=100;i++) {
switch (new { mod3 = i % 3, mod5 = i % 5 }) {