- masaito5
- 2008/08/23 18:29
try構文でwithとfinallyの両立はできるのでしょうか?
try
- アクセス数:380件
- コメント数:4件
コメント

- 3:いげ太
- 2008/08/26 15:29
IDisposable
http://research.microsoft.com/fsharp/manual/spec2.aspx#_T...
open System.IO;;
let read_first_line(file) =
use reader = new StreamReader(File.OpenRead(file)) in
reader.ReadLine();;
これは次のコードと等価です。open System.IO;;
let read_first_line(file) =
let reader = new StreamReader(File.OpenRead(file)) in
try
reader.ReadLine()
finally
( match (reader :> obj) with
null -> ()
| _ -> (reader :> System.IDisposable).Dispose() );;
.NET open System.IO;;
let read_first_line_byUse(file) =
use reader = new StreamReader(File.OpenRead(file)) in
try
reader.ReadLine()
with
e -> failwith "IO error!";;
let read_first_line_byFinally(file) =
let reader = new StreamReader(File.OpenRead(file)) in
try
try
reader.ReadLine()
with
e -> failwith "IO error!"
finally
( match (reader :> obj) with
null -> ()
| _ -> (reader :> System.IDisposable).Dispose() );;
「アンマネージ 
- 4:masaito5
- 2008/08/28 20:12
おお、丁寧な解説に心から感謝します!
関数型言語についてはある程度の前提知識があるので、F#の言語仕様にはいまのところ理解しがたいところはありませんが、.Netについてはなんの知識もありません。@ITの記事なども読んで勉強していくつもりですが、いげ太さんの解説はとても有益でした。有難うございます。
前へ 1 次へ![]()
コメントする
[block]から[/block]までの範囲はブロック表示されます。
部分的に目立たせたい時や、引用などにお使いください。
[code]から[/code]までの範囲は等幅表示されます。
ソースコードや設定ファイルの記述などにお使いください。
コメントする権限がありません











ソースなしのオレオレ解釈ですが。。
にも、Try-catch Expressions と Try-finally Expressions で別々の項が設けられていて、Try-catch-finally Expressions という項はありませんね。そして、実際に両方指定してコンパイルするとエラーになる。ならば、そういう書き方はできないのでしょう。
Donhttp://research.microsoft.com/fsharp/manual/spec2.aspx#_T...
Draft
やるのならネストですね。