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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:07:34+00:00 2026-05-26T19:07:34+00:00

I am trying to implement the quicksort algorithm in OCaml, and I thought I

  • 0

I am trying to implement the quicksort algorithm in OCaml, and I thought I had it, but it won’t compile, and I just can’t see what is wrong with it. Here’s my code:

let rec quicksort list =
    match list with
    [] -> []
    |h::t -> append((quicksort (filter (largerthan h)
    t))(quicksort(filter (smallerthan h) t)));;

let largerthan x y =
    x<y;;

let smallerthan x y =
    x>y;;

let rec append x y =
match x with
[] -> y
| h::t -> h:: append t y;;  

let rec filter f list =
   match list with
   [] -> []
   |h::t -> (if f h = true then h:: filter f t else filter f t);; 

Now, when I try to use this in OCaml, it says “Error: This expression has type ‘a -> ‘b
but an expression was expected of type ‘a” while pointing to the last line of my quicksort function.

Does anybody know what’s going wrong??

Thanks a lot!

Linus

Edit: Okay, I’ve gotten rid of the original error (thanks to ADEpt :)). However, now the function just outputs an empty list regardless of the input… Does anybody know what’s going on there??

  • 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-26T19:07:35+00:00Added an answer on May 26, 2026 at 7:07 pm

    You have extra parens in the “apply” call. Instead of:

    append((quicksort (filter (largerthan h)
    t))(quicksort(filter (smallerthan h) t))

    Write this:

    append (quicksort (filter (largerthan h) t))
    (quicksort (filter (smallerthan h) t))

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to implement QuickSort algorithm program in Java, but I'm getting incorrect answer.
Newbie programmer here trying to implement quicksort, yet it won't work. I've looked at
I'm trying to implement a Quicksort algorithm, I have read how to do it
I am trying to implement the quick sort algorithm using ruby. See what I
Just trying to implement mobFox into my app, but having trouble to make it
So I've been trying to implement a quicksort myself, just to learn something from
So I've been trying to implement a quicksort myself, but it generates a stackoverflowerror,
I am trying to implement Quick Sort algorithm. Following code works for unique elements
I am trying to program the quicksort algorithm from Cormen Algorithm Textbook. Below is
I'm trying to implement quicksort in a functional style using C# using linq, and

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.