Skip to content

Instantly share code, notes, and snippets.

@cloudRoutine
cloudRoutine / RoughMetrics.fsx
Last active July 20, 2016 12:10
Since Visual Studio won't calculate code metrics for F# projects, this script will calculate some some rough stats.
open System
open System.IO
let find_files dir = Directory.GetFiles( dir, "*.fs?", SearchOption.AllDirectories )
let not_start (s:string) p = not <| s.StartsWith p
let has_type (s:string) = if s.Contains @"type" then 1 else 0
let has_module (s:string) = if s.Contains @"module" then 1 else 0
let has_binding (s:string) = if s.Contains @"let" ||
s.Contains @"member" then 1 else 0
@mrange
mrange / optimizing_performance.md
Last active November 1, 2016 21:03
Optimizing a simple problem in F# and C++

Optimizing a simple problem

I was introduced to a simple optimization problem by one of my interns last week. He was about to participate in a friendly competition where they were asked to find a performant solution to the problem:

The problem

@mrange
mrange / json_transform.md
Last active January 23, 2017 06:53
Monadic JSON Transformers in F#
@mrange
mrange / 0_FsTransducer2.fs
Last active May 22, 2018 07:39
Another take at Transducers
module FsTransducers =
type Context =
{
mutable Continue : bool
}
static member New () : Context = { Continue = true }
type Initializer = Context -> unit
type Folder<'S, 'T> = 'S -> 'T -> 'S
type Completer<'S> = Context -> 'S -> 'S
type [<Struct>] Reducer<'S, 'T> = R of (Initializer*Folder<'S, 'T>*Completer<'S>)
let rec distribute e = function
| [] -> [[e]]
| x::xs' as xs -> (e::xs)::[for xs in distribute e xs' -> x::xs]
let rec permute = function
| [] -> [[]]
| e::xs -> List.collect (distribute e) (permute xs)
let generatePermutations r (vs : _ []) =
let inline swap f t =
module AnyTransformer =
type [<AbstractClass>] BadCause () =
class
abstract Describe : string
override x.ToString () = x.Describe
end
type [<Sealed>] MessageBadCause (msg: string) =
class
inherit BadCause ()
@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.
@enricosada
enricosada / fsharp and .net core sdk status.md
Last active March 29, 2020 13:13
.NET Core sdk, msbuild, fsharp, fsc, etc

.NET Core sdk, msbuild, fsharp, fsc, etc

How to finish/polish the integration between msbuild based .net core sdk and f# (fsc, FscTask, etc)

This doc contains current issues i known and a proposed solution (already implemented in a PR, and works) on how to fix these (obv ihmo).

AFAIK all the solution i choose are based on where dotnet/sdk, microsoft/msbuild and dotnet/cli are going with development, and updated to latest release (preview4), and vnext in development now.

TL;DR

@allykzam
allykzam / Errors.fs
Last active September 14, 2020 17:27
F# code for getting attribute data off discriminated union cases
type FatalError(message: string) =
inherit System.Attribute()
member __.Message = message
type Errors =
| [<FatalError("The value specified is currently not available")>] UnknownValue
| NotAnError
let PrintErrorMessage : Errors -> string =
fun err ->