Skip to content

Instantly share code, notes, and snippets.

@yvanin
yvanin / kCombinations.fsx
Created January 1, 2015 21:19
Producing k-combinations of a set of elements in F#
// assuming elements in a set do not repeat
let rec kCombinations k (set: 'a list) =
match k with
| 1 -> set |> List.map (fun x -> [x])
| _ ->
match set with
| [] -> []
| head::tail ->
(tail |> kCombinations (k - 1) |> List.map (fun x -> head::x))
@ (tail |> kCombinations k)
@davidfowl
davidfowl / dotnetlayout.md
Last active May 5, 2024 11:47
.NET project structure
$/
  artifacts/
  build/
  docs/
  lib/
  packages/
  samples/
  src/
 tests/
@isaacabraham
isaacabraham / idiomaticjsonserialiser.fs
Created September 7, 2014 21:17
This JSON.Net converter handles F# discriminated unions with more "idiomatic" JSON than what is generated by the current version of JSON .NET. Option types and single case DUs are transparently handled, and tuple-style properties are used rather than array notation.
namespace Newtonsoft.Json.Converters
open Microsoft.FSharp.Reflection
open Newtonsoft.Json
open System
type IdiomaticDuConverter() =
inherit JsonConverter()
[<Literal>]
@robertpi
robertpi / gist:2964793
Created June 21, 2012 09:18
F# record implementing an interface
namespace MyNamespace
type IMyInterface =
abstract GetValue: unit -> string
type MyRecord =
{ MyField1: int
MyField2: string }
interface IMyInterface with
member x.GetValue() = x.MyField2