Shameless plug – FsTest

Matthew Podwysocki finished putting together a DSL for unit testing. I imagine this only scratches the surface of what you can do with DSLs in F#.


The same approach also works for scripting too, check out this piece of Zen:


open System.IO

// Returns all the files under a given folder
let rec filesUnder rootPath =
    seq {
        for file in Directory.GetFiles(rootPath) do
            yield file
        for dir in Directory.GetDirectories(rootPath) do
            yield! filesUnder dir }
// Deletes all files
let deleteAll files = Seq.iter File.Delete files

// Notice just how flippin sweet type inference is...
// File.Delete : string -> unit
// Seq.iter    : ('a -> unit) -> #seq<'a> -> unit
// deleteAll   : #seq<string> -> unit

// The pipe-backwards operator allows you to get this to
// execute in the right order without parens around 'filesUnder'
deleteAll <| filesUnder @"C:\Logs"

Comments (2)

  1. SWEET!!!

    I’m particularly envious of yield! – it’s a shame we don’t have that in C#:

Skip to main content