Directory listing, sorting and filtering in F# Here is my first try at F#. My only functional experience is from JS.

This program takes a path as an argument and presents the user with numbered subdirs in that path. The user then selects one of the subdirs by entering it's number and the program opens explorer with the newest subdir of the selected subdir.

Any comments will be greatly appreciated — shorter and better syntax, conversions to point-free style, structuring...

open System
open System.IO

let toDirWithCreationDate path =
    (path, Directory.GetCreationTime(path))

let getLatestSubDir =
    Seq.map toDirWithCreationDate
    &gt;&gt; Seq.sortByDescending snd
    &gt;&gt; Seq.head
    &gt;&gt; fst

let getNumberedSubDirTuples =
    let ints = Seq.initInfinite (fun n -&gt; n + 1)
    Directory.GetDirectories
    &gt;&gt; Seq.sort 
    &gt;&gt; Seq.zip ints

let printDirMenu =
    Seq.iter (fun (a, b) -&gt; printfn "%A %A" a b)

let openDir (dir:string) =
    ignore (System.Diagnostics.Process.Start(dir))

[&lt;EntryPoint&gt;]
let main argv = 
    let path = argv |&gt; Seq.head
    let dirsSeq = getNumberedSubDirTuples path
    printDirMenu dirsSeq
    let dirNr = System.Console.ReadLine()
    let dir = 
        dirsSeq 
        |&gt; Seq.tryFind(fun (a,b) -&gt; a = int(dirNr))
    let latestSubdir = 
        match dir with
            | Some d -&gt; Directory.GetDirectories (snd d) |&gt; getLatestSubDir |&gt; openDir
            | None -&gt; printfn "Invalid input"
    0
I am not sure if I can summarize the changes I made better, but I made several refactorings and better error handling (when inputing a string, for example, your program crashed.) I also chose to make it zero-indexed, rather than 1-indexed, mostly to simplify the code.

open System
open System.IO

let getLatestSubDir = Seq.maxBy Directory.GetCreationTime // Refactored
let sortedSubDirs = Directory.GetDirectories &gt;&gt; Seq.sort // Refactored
let printDirMenu = 
    sortedSubDirs &gt;&gt; Seq.iteri (fun idx path -&gt; printfn "%d %s" idx path)
let openDir (dir : string) = System.Diagnostics.Process.Start(dir) |&gt; ignore

[&lt;EntryPoint&gt;]
let main argv = 
    let path = argv |&gt; Seq.head
    printDirMenu path
    let input = System.Console.ReadLine()
    match Int32.TryParse(input) with
    | true, n -&gt; 
        let dir = 
            path
            |&gt; sortedSubDirs
            |&gt; Seq.tryItem n
        match dir with
        | Some d -&gt; 
            Directory.GetDirectories(d)
            |&gt; getLatestSubDir
            |&gt; openDir
        | None -&gt; printfn "Invalid input"
    | _ -&gt; printfn "Invalid input"
    Console.ReadKey() |&gt; ignore
    0


It is definitely possible to factor the sorting so it is only done once, rather than twice in my code.

The code also crashes when the chosen folder doesn't have any sub folders.