1

たとえばF x y、カリー化関数として定義し、環境で部分関数(F x)が頻繁に使用される場合、パフォーマンスの観点から常にlet binding名前付き関数にする必要がありますか? property(たとえば、キャッシュされたのと比較して、などobjectをキャッシュする必要がない場合が多いため)propertyArray.Length

 let Gofrom (board: int[][]) (color: int) (reelID, reelPosition) (direction: Direction) =
    let rec walkfrom x =
        match direction.Target x with
        | (a, _ | _, a) when a = -1 || a = board.Length -> x
        | a, b when board.[a].[b]= color -> walkfrom (a, b)
        | _ -> x
    walkfrom (reelID, reelPosition)

 let rec Gofrom (board: int[][]) (color: int) (reelID, reelPosition) (direction: Direction) =
        match direction.Target (reelID, reelPosition) with
        | (a, _ | _, a) when a = -1 || a = board.Length -> (reelID, reelPosition)
        | a, b when board.[a].[b]= color -> Gofrom board color (a, b) direction
        | _ -> (reelID, reelPosition)
4

1 に答える 1

3

There should be no difference in performance, but I would definitely use the first form since it makes clear which args do not change between invocations.

Incidentally, this isn't really about currying as you're refactoring code into a separate function (closure) to avoid passing args around.

于 2012-09-13T17:10:35.440 に答える