私はF#関数を持っている:F#値の制限
let removeEven (listToGoUnder : _ list) =
let rec listRec list x =
match list with
| [] -> []
| head::tail when (x%2 = 0) -> head :: listRec (tail) (x+1)
| head::tail -> listRec (tail) (x+1)
listRec listToGoUnder 0
それはリストの中にもインデックスですべての要素を削除します。 私はリストをいくつかのimputを与えると動作します。removeEven ['1';'2';'3']
のように私は['1';'3']
を取得します。しかし、パラメータとして空のリストを挿入すると、このエラーが発生します。
stdin(78,1): error FS0030: Value restriction. The value 'it' has been inferred to have generic type
val it : '_a list Either define 'it' as a simple data term, make it a function with explicit arguments or, if you do not intend for it to be generic, add a type annotation.
助けてください、誰か?
注意、それはより慣用的かもしれない。 – kvb
引数が '[]'の場合、提案されたremoveOdd関数は失敗します。 私はこれを一般的な方法で解決しようとしていますが、「エラーFS0030:値の制限」なしで '[]'のケースを処理することはできません。 このような機能を本当に汎用的にすることは可能ですか? – TurboHz