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

  • SEARCH
  • Home
  • 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 8922213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:46:37+00:00 2026-06-15T06:46:37+00:00

I have made this code: let rec foo1 z = function | [] ->

  • 0

I have made this code:

let rec foo1 z = function
  | [] -> []
  | x::xs when x = z -> x::(foo1 x xs)
  | x::xs -> foo1 z xs

but I want a more complex version of this function with a new function which is of type int -> int -> bool as first argument. This function will test the integer argument against all the elements of the list, the elements that yields true when the operator is applied should be placed in the return list

Example:

let eq x y = x = y
let lt x y = x < y
let gt x y = x > y

foo2 eq 2 [1;2;4;2;5] => [2;2]
foo2 lt 2 [1;2;4;2;5] => [4;5]
foo2 gt 2 [1;2;4;2;5] => [1]
  • 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-06-15T06:46:38+00:00Added an answer on June 15, 2026 at 6:46 am
    /// Pass a function as an argument 
    let rec filterByVal fn z = function 
        | [] -> [] 
        | x::xs when fn z x -> x::(filterByVal fn z xs) 
        | _::xs -> filterByVal fn z xs
    
    /// Use anonymous functions
    filterByVal (fun z x -> z = x) 2 [1;2;4;2;5] // [2; 2]
    filterByVal (fun z x -> z < x) 2 [1;2;4;2;5] // [4; 5]
    filterByVal (fun z x -> z > x) 2 [1;2;4;2;5] // [1]
    
    /// Or use symbolic infix functions
    filterByVal (=) 2 [1;2;4;2;5]
    filterByVal (<) 2 [1;2;4;2;5]
    filterByVal (>) 2 [1;2;4;2;5]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a line, which is a sprite made by using this code CGPoint
Hi have made this function which is made to replicate an error that I
Let's say I want to have a function which reads data from the SerialPort
I have made this code: var foo=document.createElement(div); var childs=foo.getElementsByTagName(*); console.log(childs.length);//0 OK var a=document.createElement(a); foo.appendChild(a);
I have made this code to open a database(created in SQLite browser) stored in
I have a problem, and I made this test code to show you my
I have made a program code for shared preference in android. But i am
This is a chart that I have made using d3.js. I want my bars
Let's say I have a manufacturing scheduling system, which is made up of four
I have made this centered navigation bar, and I wanted to add a :active

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.