dotnet new console -lang 'f#'
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
let rec sum lst count =
match lst with
| head :: tail -> sum tail (count + head)
| [] -> count
count [1,2,3,4] 0
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)
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"
Using tuples can reduce boilerplate code
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 ...