Limit the value of F # in an empty list

I have a F # function:

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

It removes all elements with an even index in the list. It works if I give the list some imput, for example removeEven ['1';'2';'3']I get ['1';'3']which I should. But when I insert an empty list as a parameter, I get this error:

stdin (78.1): error FS0030: value limitation. The value "it" was supposed to have a common type

val it: '_a list Define' it 'as a simple data term, make it a function with explicit arguments, or if you do not intend to be general, add a type annotation.

Help someone?

+5
source share
1 answer

([]) ; . , []. :

let results = removeEven ([]: int list)

, @kvb:

let results: int list = removeEven []

, , , removeOdd, 0, . , , , x :

let rec removeOdd = function
    | [] -> []
    | [x] -> [x]
    | x::_::xs -> x::removeOdd xs
+7

All Articles