Skip to content

Instantly share code, notes, and snippets.

@jsakamoto
Created August 27, 2012 12:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsakamoto/3487987 to your computer and use it in GitHub Desktop.
Save jsakamoto/3487987 to your computer and use it in GitHub Desktop.
しかしこれはビルドエラー(F#のレコード型(下記 MyFile)はnullになるはずがない)。でもprintfnの行を外すとビルドは通るので実行してデバッガで見るとnullになってる。
open System.IO
open System.Linq
type MyFile = {Name:string; Size:int64}
let toMyFile (f:FileInfo) = {Name=f.Name; Size=f.Length}
let dir = new DirectoryInfo("c:\\")
let fileOfFoo =
dir.GetFiles()
|> Array.map toMyFile
|> fun x -> x.FirstOrDefault(fun f -> f.Name = "foo")
printfn "%s" (if fileOfFoo = null then "null!" else "exists!")
// The type 'MyFile' does not have 'null' as a proper value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment