Skip to content

Instantly share code, notes, and snippets.

@dvdsgl
Created May 22, 2013 18:28
Show Gist options
  • Save dvdsgl/5629783 to your computer and use it in GitHub Desktop.
Save dvdsgl/5629783 to your computer and use it in GitHub Desktop.
Using F# active patterns to avoid boolean blindness.
let (|File|Directory|Missing|) path =
if Directory.Exists path then Directory
elif File.Exists path then File
else Missing
let cp_r source dest =
match source, dest with
| Missing, _ -> failwithf "missing file"
| File, File -> cp source dest
| File, Directory -> ...
| Directory, Directory -> ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment