私が持っている機能を、私は今それを再帰的にしたいメイキング機能
let simpleSum n =
let s = n * (n+1)/2
printf "%A " s
let result = simpleSum 10
。付加変数を持たないテール再帰が好ましい。私はエラーに遭遇しif n <= 0 then 0
let rec recSum n =
if n <= 0 then
0
else
recSum n*(n+1)/2
recSum 4
:
FS0020: The result of this expression is implicitly ignored.
Consider using 'ignore' to discard this value explicitly, e.g. 'expr :> ignore',
or 'let' to bind the result to a name, e.g. 'let result = expr'.
私はこれをどのように修正すればよい
私の声明に何か問題はありますか?私は変数を避けたい。
何が問題なのですか?どのようなエラー/問題が起きていますか? – mosca125
whileループのポイントは何ですか?どの場合には、結果はちょうど 'let sum n = n *(n + 1)/ 2'とは異なるでしょうか? – sepp2k
whileループは必要ではありませんが、私の割り当てには必須条件でした。 エラー: FS0020:この式の結果は暗黙的に無視されます。この値を明示的に破棄するには、「無視」を使用してください。 'expr:> ignore'、または 'let'を使用して結果を名前にバインドします。 'let result = expr'とする。 ここでは変数を避けたいと思います。 – kthonenice