Skip to content

Instantly share code, notes, and snippets.

module CoreTypes =
type Result<'TSuccess,'TFailure> =
| Success of 'TSuccess
| Failure of 'TFailure
type Request = {name:string; email:string}
module BindExample1 =
@swlaschin
swlaschin / type-dependency-graph.fsx
Last active March 4, 2021 19:24
This script analyzes the dependencies between top level types in a .NET Assembly. It is then used to compare the dependency relationships in some F# projects with those in some C# projects.
(*
This script analyzes the dependencies between top level types in a .NET Assembly.
It is then used to compare the dependency relationships in some F# projects with those in some C# projects.
Note that no attempt has been made to optimize the code yet!
REQUIRES:
* Mono.Cecil for code analysis
From http://www.mono-project.com/Cecil#Download
@swlaschin
swlaschin / type-dependency.csv
Last active December 18, 2015 06:59
Raw data for type dependencies in C# and F# projects
We can make this file beautiful and searchable if this error is corrected: It looks like row 2 should actually have 1 column, instead of 21. in line 1.
# C# projects
Project,CodeSize,TopLevelTypes,AuthoredTypes,AllTypes,AllTotalDepCount,AllOneOrMoreDepCount,AllThreeOrMoreDepCount,AllFiveOrMoreDepCount,AllTenOrMoreDepCount,AllMaxComponentSize,AllCycleCount,AllCycleParticipants,PubTotalDepCount,PubOneOrMoreDepCount,PubThreeOrMoreDepCount,PubFiveOrMoreDepCount,PubTenOrMoreDepCount,PubMaxComponentSize,PubCycleCount,PubCycleParticipants
ef,269521,514,565,876,2354,393,260,162,69,79,14,123,255,129,18,6,0,7,1,7
jsonDotNet,148829,215,232,283,913,149,90,65,31,83,3,88,253,79,39,13,2,11,1,11
nancy,143445,339,366,560,1132,265,138,76,21,21,6,35,650,254,87,34,6,2,2,4
cecil,101121,240,245,247,1145,174,102,54,32,123,2,125,416,95,53,29,11,50,1,50
nuget,114856,216,237,381,833,154,93,57,26,10,4,24,373,121,45,22,5,0,0,0
signalR,65513,192,229,311,641,127,65,37,19,7,3,14,269,103,40,11,2,5,1,5
nunit,45023,173,195,197,499,130,67,23,7,78,2,80,330,120,28,7,3,48,1,48
==========================
Proposal for automatic integration of F# signature (.fsi) file and "code behind" (.fs) file.
==========================
Currently F# signature files must be maintained separately from the related .fs file,
which is inconvenient at best.
This document describes two different proposals that could alleviate this inconvenience.
* Approach 1: Have the signature file generated from the .fs file
I find right pipe useful on those occasions when you have a chain of pipes,
but for one of them you want to pass the data in as the FIRST param,
rather than the last.
Here's an example:
// setup some functions
let replace (oldS:string) newS (a:string) = a.Replace(oldS,newS)
let add a b = sprintf "%s %s" a b
let toUpper (a:string) = a.ToUpper()
System.IO.Directory.SetCurrentDirectory __SOURCE_DIRECTORY__
// The following DLLs were fetched using NuGet
#r @".\packages\FsCheck.0.9.2.0\lib\net40-Client\FsCheck.dll"
#r @".\packages\NUnit.2.6.3\lib\nunit.framework.dll"
open FsCheck
open NUnit.Framework
// ======================================
// ==============================
// This gist is in response to
// http://programmers.stackexchange.com/questions/228939/how-to-improve-upon-blochs-builder-pattern-to-make-it-more-appropriate-for-use
//
// This is a simple bit of code to do the same thing using the Either monad (e.g. success/failure) and applicatives
// This code is (a) more generic (b) much shorter (c) more type safe
//
// Compare with the Java code at https://gist.github.com/swlaschin/9009343
// ==============================
// ==============================
// This gist contains the code from
// http://programmers.stackexchange.com/questions/228939/how-to-improve-upon-blochs-builder-pattern-to-make-it-more-appropriate-for-use
//
// Compare with the functional version at https://gist.github.com/swlaschin/9008814
// ==============================
// ==========================================
// UserConfig.java
@swlaschin
swlaschin / SourceLineCount_Roslyn.fsx
Last active December 27, 2015 21:48
F# scripts for analysis of Roslyn vs F# compiler
(*
This script counts lines in C# and F# projects.
It is used to compare the "useful lines" in F# projects with those in C# projects.
Copied from Kit Eason's code at http://www.fssnip.net/h4
REQUIRES:
* FSharp.Charting for charts
via NuGet

#The Functional Programmers Cheat Sheet for NDC Oslo 2014

This year NDC Oslo has a full three-day functional programming track with an amazing lineup. If you agree that the future of programming is FP, use this as your "auto pilot" guide on what sessions to attend.

Cheer for sessions on Twitter using the #ndcoslo and #fptrack hashtags.

[The full agenda (including non-fp sessions) is here].