我想知道F#中是否有像Haskell的where
子句中的任何內容。這將允許以變換以下代碼F#與Haskell的where子句一樣嗎?
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)
入(IMO)稍微更可讀的版本
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)
,因爲它顯示了功能的核心部分的第一和實現細節以後(挑剔,我認爲!)。
我的猜測是F#解析代碼文件的方式是不可能的。我對嗎?看看F#的關鍵字引用似乎沒有炫耀我想要的任何東西。如果它不存在,有沒有其他方法可以更好地分解出所顯示的代碼?我會說這是好的,但你永遠不會知道..