Skip to content

Instantly share code, notes, and snippets.

(*
RecursiveTypesAndFold-3b-database.fsx
Example: Storing a tree in a database
Related blog post: http://fsharpforfunandprofit.com/posts/recursive-types-and-folds-3b/
*)
// ==============================================
// PART 3b - Storing a tree in a database
(*
RecursiveTypesAndFold-3b-json.fsx
Example: Serializing and deserializing a tree to JSON
Related blog post: http://fsharpforfunandprofit.com/posts/recursive-types-and-folds-3b/
*)
// ==============================================
// PART 3b - Serializing and deserializing a tree to JSON (without error handling)
@swlaschin
swlaschin / RecursiveTypesAndFold-3b-json-with-error-handling.fsx
Last active August 30, 2015 19:53
Serializing and deserializing a tree to JSON (with error handling). Related blog post: http://fsharpforfunandprofit.com/posts/recursive-types-and-folds-3b/
(*
RecursiveTypesAndFold-3b-json-with-error-handling.fsx
Related blog post: http://fsharpforfunandprofit.com/posts/recursive-types-and-folds-3b/
*)
// ==============================================
// PART 3b - Serializing and deserializing a tree to JSON (with error handling)
// ==============================================
module SimplifiedVendorExample =
type Product =
| Bought of string
| Made of Product list
let rec cataProduct fBought fMade product :'r =
let recurse = cataProduct fBought fMade
match product with
(*
RecursiveTypesAndFold-1b.fsx
Related blog post: http://fsharpforfunandprofit.com/posts/recursive-types-and-folds-1b/
*)
// ==============================================
// PART 1b - Catamorphism examples
// ==============================================
module CoreTypes =
type Result<'TSuccess,'TFailure> =
| Success of 'TSuccess
| Failure of 'TFailure
type Request = {name:string; email:string}
module BindExample1 =
@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
@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
==========================
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()