1
私は、これらのタイプがあります。F#のコンパターンマッチ機能
type ShouldRetry = ShouldRetry of (RetryCount * LastException -> bool * RetryDelay)
and RetryCount = int
and LastException = exn
and RetryDelay = TimeSpan
type RetryPolicy = RetryPolicy of ShouldRetry
は、今私は、再試行の構成可能性をしたいです。このような何か:
let serverOverloaded = [| exnRetry<TimeoutException>;
exnRetry<ServerBusyException> |]
|> Array.map (fun fn -> fn (TimeSpan.FromSeconds(4.0)))
let badNetwork = [||] // etc
let compose p1 p2 =
// http://fssnip.net/7h
RetryPolicy(ShouldRetry((fun (c,e) ->
let RetryPolicy(ShouldRetry(fn)) = p1
let RetryPolicy(ShouldRetry(fn')) = p2
let (cont, delay) = fn c,e
if cont then cont, delay
else
let (cont', delay') = fn' c,e
cont', delay')))
let finalPolicy = serverOverloaded |> Array.scan compose (RetryPolicies.NoRetry())
しかし、私は、「値またはコンストラクタ 『FN』が定義されていません」と言って、fn
、delay
とfn'
にコンパイルエラーを取得しています。