Skip to content

Instantly share code, notes, and snippets.

View goswinr's full-sized avatar

Goswin Rothenthal goswinr

View GitHub Profile
anonymous
anonymous / gist:4409734
Created December 29, 2012 22:32
F# inline and effects on performance
open System
open System.Collections.Generic
[<Struct>]
type Pair<'a when 'a: equality> =
val v: 'a
val w: 'a
new(x,y)= {v=x;w=y}
type Tone =
| Rest = 0
| GbelowC = 196
| A = 220
| Asharp = 233
| B = 247
| C = 262
| Csharp = 277
| D = 294
| E = 330
@sgoguen
sgoguen / merkle-tree.fsx
Created February 16, 2017 21:30
Merkle Trees
open System.IO
open System.Collections.Concurrent
// A Merkle tree for a file system might look like this
// PASTE!!
let isDirectory(path:string) =
let attr = File.GetAttributes(path)
attr.HasFlag(FileAttributes.Directory)
@ptrelford
ptrelford / JsonParser.fs
Last active May 7, 2018 14:05
JSON Parser
type json =
| Number of float
| String of string
| Boolean of bool
| Array of json list
| Object of (string * json) list
| Null
static member (?) (this,name:string) =
match this with
| Object xs -> xs |> List.find (fst >> (=) name) |> snd
@realvictorprm
realvictorprm / PaketDependencyManagementMadeEasy.fsx
Last active June 12, 2018 19:41
A must have for your script file to ease spreading a small proof of concept with dependencies!
open System
open System.IO
open System.Diagnostics
let downloadDependencies deps =
Environment.CurrentDirectory <- __SOURCE_DIRECTORY__
if not (File.Exists "paket.exe") then
async {
let url = "http://fsprojects.github.io/Paket/stable"
@jesterKing
jesterKing / common.fs
Created June 1, 2016 21:56
Grasshopper F# sample code. Note that the code in this gist isn't complete - it probably won't compile. But it should show the basic idea of what goes in a F# component for Grasshopper.
namespace CommonStuff
open Microsoft.FSharp.Reflection
open System
open System.Text
open System.Collections.Generic
open System.Linq
open System.Drawing
open System.Windows.Forms
#I __SOURCE_DIRECTORY__
#r "libs/NuGet.Core.dll"
#r "System.Xml.Linq"
open NuGet
open System
open System.IO
module NuGet =
// This is am example of an immediate write / random access cursor for Excel with basic formatting options.
// Implementation is based on a concrete, non generic writer monad with no payload ("do!"" only) (only state).
// Instead of directl writing to excel, an alternatives would be a random acces to a
// copy-on-write list (or even a mutable array) and then bulk-write the result to excel in one shot.
// When only forward access would have been required, a simple seq expression with yields would have been enough.
// Anyway, it is a demonstration on how to "hide" pseudo-mutable state that is passed through a computation.
//
// I personally use it for generating reports based on various data sources.
@jesterKing
jesterKing / GhFsharpTest.fs
Last active June 12, 2019 07:09
F# sample component for testing on Mac Rhino Grasshopper (v6, aka WIP)
namespace GhFsharpTest
open Grasshopper.Kernel
open Grasshopper.Kernel.Types
type Priority() =
inherit GH_AssemblyPriority()
override u.PriorityLoad() =
GH_LoadingInstruction.Proceed
@mrange
mrange / fsharp_advent_2016_12_10.md
Last active December 14, 2019 21:44
F# Advent 2016 (English) - December 10 - Implementing a persistent hash map.