Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7544979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:48:45+00:00 2026-05-30T08:48:45+00:00

I have a F# function: let removeEven (listToGoUnder : _ list) = let rec

  • 0

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 at an even index in a list.
It works if I give the list some imput, like removeEven ['1';'2';'3'] I get ['1';'3'] which I am supposed to. But when I insert a empty list as parameter, I get this error:

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.

Help, anybody?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T08:48:47+00:00Added an answer on May 30, 2026 at 8:48 am

    The empty list ([]) is quite special; it can be a list of any type. Therefore, the compiler complains that you don’t have a specific type for []. Adding type annotation on the argument helps to solve the problem:

    let results = removeEven ([]: int list)
    

    or more idiomatic type annotation as suggested by @kvb:

    let results: int list = removeEven []
    

    This is probably beyond the question, but your function should be named as removeOdd since indices often start from 0 and your function removes all elements with odd indices. Moreover, things are much more clear if you use pattern matching on first two elements of the list rather than keep a counter x for checking indices:

    let rec removeOdd = function
        | [] -> []
        | [x] -> [x]
        | x::_::xs -> x::removeOdd xs
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have these these two functions //Remove all even indexed elements from a list
Let's say we have a simple function defined in a pseudo language. List<Numbers> SortNumbers(List<Numbers>
If I have a short list (let's say two or three elements) I would
let say i have function like below function doSomethingNow(){ callSomethingInFutureNotExistNow(); } at the moment
Let's say you have a function that returns a date: Date myFunc(paramA, paramB){ //conditionally
Let's say I have the following function: sumAll :: [(Int,Int)] -> Int sumAll xs
Let's assume we have a template function foo: template<class T> void foo(T arg) {
Let's say we have the following function: foo <- function(x) { line1 <- x
Let's say that I have an Erlang function, with spec. -spec foo(integer(), string()) ->
Let's say I have a 1D Gaussian function. Its length is 600. I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.