Skip to content

Instantly share code, notes, and snippets.

@marklam
marklam / Pickling.fsx
Created August 14, 2023 15:17
Attempting to pickle ImmutableList
#r "nuget:FsPickler"
open System.IO
open System.Collections.Immutable
open MBrace.FsPickler
let mkPickler<'t> (resolver : IPicklerResolver) =
let seqPickler = resolver.Resolve<'t seq> ()
let writer (w : WriteState) (ns : ImmutableList<'t>) =
@marklam
marklam / EqualityBenchmarks.fs
Created May 23, 2023 18:23
Benchmark on equality of F# types containing large arrays
namespace Benchmarks
open BenchmarkDotNet.Attributes
type SingleCaseDU = | One of int[]
type TwoCaseDU = | Empty | Full of int[]
type Record = { Values : int[] }
type [<Struct>] StructRecord = { Values : int[] }
module Custom =
@marklam
marklam / Dependencies.fsx
Last active June 25, 2020 12:45
Change class to module
// How to deal with nested dependencies?
// Background : https://bartoszsypytkowski.com/dealing-with-complex-dependency-injection-in-f/
open System
// Services
type ILogger =
abstract LogMessage : string -> unit
@marklam
marklam / PulumiFragment.fs
Created January 22, 2020 13:53
Pulumi FSharp code to create an API gateway entry for a lambda function that's hosting Asp.net core (eg in giraffe)
let infra () =
...
let openApiSpec (name, arn) =
let quotedTitle = "\"" + name + "api\""
let quotedUri = sprintf "\"arn:aws:apigateway:%s:lambda:path/2015-03-31/functions/%s/invocations\"" Pulumi.Aws.Config.Region arn
"""{
"openapi": "3.0.1",
"info": {
@marklam
marklam / CannotRegress.csv
Created January 27, 2015 16:27
Data that is failing Regularization in Accord
In1 In2 Out
15.3 0 1
15 0 1
3.2 1 1
7.5 0 0
10.2 0 1
10.9 0 1
14.5 0 0
5.7 0 0
5 0 1