Udostępnij za pośrednictwem


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:

 #light

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