Make a project

dotnet new console -lang 'f#'

Run from a script file

dotnet fsi Program.fsx

This is faster At the end, remember to add in the main function, rename to Program.fs and test using dotnet run

Sum items in a list

let rec sum lst count =
    match lst with
    | head :: tail -> sum tail (count + head)
    | [] -> count

count [1,2,3,4] 0

Recurse through a tree and get some number

    let rec JunctionPath (pSystem:unionType) (sName:string) (juncList:List<string>) = 
        match pSystem with
        | System(name,aNumber) -> if name = sName then juncList else []
        | Junction(name,aList) -> if name = sName then juncList else splitList aList sName (juncList @ [name])

    and splitList (list:List<unionType>) (sName:string) (juncList:List<string>)=
        match list with 
        | [] -> []
        | head::tail -> (JunctionPath head sName juncList)@(splitList tail sName juncList)

Compare two lists from the tail

let rec pathComparison (path1:List<string>) (path2:List<string>) (default:string) =
    match path1 with
    | [] -> default
    | head::tail -> if path2.Head = head then pathComparison tail path2.Tail head else default

let commonPath network system1 system2 =
    let path1 = JunctionPath network system1
    let path2 = JunctionPath network system2
    if (List.length(path1) > List.length(path2)) then pathComparison path2 path1 "Error"
    else pathComparison path1 path2 "Error"

Working with tuples

Using tuples can reduce boilerplate code

Using selection options

Pass an extra argument in the form select.option having previously specified the select union type. Compare the actuals with an if statement: if (flag = select.option1) then ...