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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:11:28+00:00 2026-06-05T04:11:28+00:00

I got this function: foo [] = [] foo (x:xs) = foo us ++

  • 0

I got this function:

foo [] = []
foo (x:xs) = foo us ++ foo ys
where us = filter (<=x) xs
      ys = filter (>=x) xs

type of this function is Ord a => [a] -> [b] .

I don’t understand why the output type is [b] and not [a]. I think it should be [a] since the elements of the output list will be part of the elements of the input list.

I am using Hugs, but I don’t think it changes anything.

  • 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-05T04:11:30+00:00Added an answer on June 5, 2026 at 4:11 am

    The type Ord a => [a] -> [b] is internally consistent, though!

    The problem is that you never actually add any elements from the input list to the output list. You need a base case; something like foo [x] = [x]. As it stands, you never actually say that any elements from the input list get added to the output list; the result of this function will always be [], which can have type [b] regardless of input.

    If you’re trying to implement something like Quicksort here, though, there are two logical problems in your implementation:

    1. x, the pivot, doesn’t get added to the output list.
    2. Any values in the list that are equal to x other than x itself will be added twice, once from us and once from ys.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the end, I got this function. I don't know whether it's normal or
I've got a JavaScript object, built this way: function foo() { this.length = 0;
I got this code: function zeroPad(num, places) { var zero = places - num.toString().length
I've got this simple function which displays a message to the user. If I
I've got this jQuery function: function phpmail(){ $.post('mail.php',{name:$(#name).val()}, function(out){ alert(out); }); } and this
I got this from for a login form tutorial: function sanitize($securitystring) { $securitystring =
I've got this code in the InitInstance function of a class that extends WinApp:
I've got this script on my website : $(document).ready(function() { function filterPath(string) { return
So i got this snippet of code: $(document).ready(function () { var replacementDoneIn = $(body).html();
I've got a .js file that has this function in it: function showDialog(divID) {

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.