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 918447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:22:35+00:00 2026-05-15T18:22:35+00:00

F# function Problem: given a list of items e.g.: [5;10;2;53;4] and a Search Index,

  • 0

F# function

Problem:

given a list of items e.g.:

["5";"10";"2";"53";"4"]

and a Search Index, I require a function such that it compares the current given index against its neighbor, returning the largest index

Example:

  • Given Index 1 will return Index value 2 (because 10 is greater than 5).
  • Given Index 4 will return Index 4 (because 53 is greater than 4)

Currently this is my function. It does not compile:

let GetMaxNode (x:Array) Idx = if x.[Idx] > x.[Idx+1] then  Idx else If  x.[Idx] < x.[Idx+1] then  Idx+1

The errors I’m getting for all the x’ are:

The field, constructor or member 'Item' is not defined (FS0039)

And also the second If:

The value or constructor 'If' is not defined (FS0039)

I suspect I’m still thinking in a procedural way, I was thinking about using pattern matching, however I was not confident enough with the syntax to try it.

Please can you also explain the answer as well, as I’m trying to learn F#, just the solution will not help me much.

  • 1 1 Answer
  • 1 View
  • 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-15T18:22:36+00:00Added an answer on May 15, 2026 at 6:22 pm

    Here’s some code based on yours:

    let GetMaxNode (x:_[]) idx = 
        if x.[idx] > x.[idx+1] then  
            idx 
        elif x.[idx] < x.[idx+1] then  
            idx+1 
        else
            idx // same, return this one
    

    The main changes are

    • to declare an array type, say <typename> []. In this case, we don’t care about the type, so I use _ as a “don’t care, please go infer the right thing for me” type variable.
    • “else if” is spelled elif in F#
    • need an else case for if equal
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.