2011-09-04 13 views
7

F#にHaskellのwhere句のようなものがあるかどうか疑問に思っていました。これは、それが後で(つべこべ第一及び実装の詳細機能の中核部分を示しているように(IMO)やや可読バージョンF#にはHaskellのwhere節のようなものがありますか?

let roulleteWheel numberGenerator (scoredPopulation:ScoredPopulation) = 
    Seq.pick isMatch (Seq.zip scoredPopulation accumulatedScores) 
    where 
    let targetScore = 
     let totalScore = totalPopulationFitness scoredPopulation 
     Seq.head (numberGenerator 0.0 totalScore) 

    let isMatch (score, accumulatedScore) = 
     if (accumulatedScore >= targetScore) then 
     Some(score) 
     else 
     None 

    let accumulatedScores = 
     let scores = Seq.map (fun (_, score) -> score) scoredPopulation 
     Seq.skip 1 (Seq.scan (+) 0.0 scores) 

に次のコード

let roulleteWheel numberGenerator (scoredPopulation:ScoredPopulation) = 
    let targetScore = 
    let totalScore = totalPopulationFitness scoredPopulation 
    Seq.head (numberGenerator 0.0 totalScore) 

    let isMatch (score, accumulatedScore) = 
    if (accumulatedScore >= targetScore) then 
     Some(score) 
    else 
     None 

    let accumulatedScores = 
    let scores = Seq.map (fun (_, score) -> score) scoredPopulation 
    Seq.skip 1 (Seq.scan (+) 0.0 scores) 

    Seq.pick isMatch (Seq.zip scoredPopulation accumulatedScores) 

を形質転換するために可能にしますみなす!)。

私の推測では、F#がコードファイルを解析する方法では不可能だと思います。私は正しい? F#のキーワードの参照は、私が探しているようなものではないようです。それが存在しない場合は、表示されているコードをさらに除外する他の方法はありますか?私はそれがそのまま大丈夫だと言うでしょうが、あなたは決して知りません。

答えて

6

悲しいことに、さらに悲しいことに、F#の問題はもっと大事です。 相互回帰let rec ... and ...を使用できますが、どこと同じではありません。

1

F#にはこのようなキーワードはありません。両方のコードの違いは、1つは定義が最初、その後が2番目のコードでは逆であることです。

0

最近のバージョンのF#の "in"キーワードは、Haskellの "where"節と似ていませんか?

関連する問題