English 中文(简体)
执行F# 工作流程建设者:处理工厂的例外情况。
原标题:Implementing F# workflow builders: handling exceptions in for..in..do constructs
  • 时间:2010-12-05 21:45:17
  •  标签:
  • f#

继续探讨 F# workflow Buildingers, I 决定对建筑商进行例外处理,特别是在“for.in.do”建筑中。

这一试验的终极目标是工作流程建设者,即使在出现例外情况时,也将继续处理顺序。

The below, for example, doesn t work, because the For method of the builder does not appear to get called until after the point where the exception occurs (at the first Directory.EnumerateFiles(dir) call)

type failSafeSeq() =
    member this.For(seq1, mapFunction) =
        try
            seq1 |> Seq.collect mapFunction
        with
            ex -> Console.WriteLine ex
                  Seq.empty
    member this.Yield(yieldExpr) = yieldExpr |> Seq.singleton
    member this.YieldFrom(yieldBang) = yieldBang
    member this.Combine(a, b) = Seq.append a b
    member this.Delay(delayFun) = delayFun()
    member this.Zero() = Seq.empty 

let failSafe = new failSafeSeq();

let rec allFilesSeq dir =
    failSafe { for file in Directory.EnumerateFiles(dir) do yield file
               for subdir in Directory.EnumerateDirectories dir do yield! (allFilesSeq subdir) }

[<EntryPoint>]
let main args =
    allFilesSeq "C:\System Volume Information\" //almost guaranteed to cause an UnauthorizedAccessException on Windows systems at the first Directory.EnumerateFiles(dir) call.
    |> Seq.iter Console.WriteLine
    0

利用F#工作流程是可能的?

最佳回答

页: 1

... for pat in expr do cexpr ...

翻译

... b.For(expr, fun pat -> cexpr) ...

可在<代码>之前评价<代码>。 ,如果投了弃权票,则上至。 不适用

顺便说一句,您的战略也不会发挥作为人的作用,因为seqs are lazy, and e.gSeq.org。 通常不会抛弃(此外,要求它和评估顺序的法典可能会导致法典管理这种 throw。

还可以采取其他一些方式,以恢复<代码>以下...... 我认为,工作流程或许是错误的做法,相反,你只想就<条码>以下的制作和绘图做一些总结。

真正的最终目标是什么? http://www.un.org/Depts/DGACM/index_spanish.htm 似乎对我不有用,你打算如何适用?

问题回答

暂无回答




相关问题
F#: Storing and mapping a list of functions

I have a number of events that happen in a game. I want to control the time and order at which these events occur. For example: Event 1: Show some text on screen for N frames & play a sound ...

Creating Silverlight 3 applications with F#

Is there an easy way to create Silverlight 3 applications with F# (October CTP)? I have seen the F# for Silverlight, but that only works with the May CTP. I am using Visual Studio Integrated Shell ...

How To Change List of Chars To String?

In F# I want to transform a list of chars into a string. Consider the following code: let lChars = [ a ; b ; c ] If I simply do lChars.ToString, I get "[ a ; b ; c ]". I m trying to get "abc". I ...

Unzipping ZLIB compressed portions of a binary file

I m reading a file(a flash swf) from .Net 3.5 that has a header which states whether the body of the file/Stream is compressed or not. However, I m having problems-after I rewrap the basic File ...

Pretty print a tree

Let s say I have a binary tree data structure defined as follows type a tree = | Node of a tree * a * a tree | Nil I have an instance of a tree as follows: let x = Node (Node (...

F# String Pattern-Matching with Wildcards

As part of a project I have assigned myself as a way of improving my knowledge of F# and functional programming in general, I am attempting to write a string pattern-matching algorithm from scratch ...

热门标签