C#の型推論は怠けすぎ
2010-09-29(via やねうらおさんとこ)
C#はバランスと取れた良い言語ですが、あえて欠点を挙げると型推論がイマイチですよね。
using System;
using System.Collections.Generic;
module M
{
static Main() : void
{
// C#のvarに近いが初期化は必須ではない
// mutable x = null;もOK。この場合、代入は参照型のみになる
mutable x;
try {
// 適当なコード
x = Dictionary.[int, string]();
x[10] = "ten";
}
catch {
| x is Exception => Console.WriteLine(x);
}
finally
{
match (x)
{
| y is IDisposable => y.Dispose()
| _ => ();
}
}
}
}