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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:31:38+00:00 2026-06-01T14:31:38+00:00

I have a function (frequency) which that counts how many times each distinct value

  • 0

I have a function (frequency) which that counts how many times each distinct value in a list occurs in that list. For example,

frequency "ababca" 

should return:

[(3, 'a'), (2, 'b'), (1, 'c')].

This works fine but now I need to sort the list using the first element within the list of the list using this function.

results   :: [Party ] -> [(Int, Party)]
results  xs = ??? frequency (sort xs) ??? 

example of desired output:

[(1, "Green"), (2, "Red"), (3, "Blue")]

The above does not work, I have no idea what I can do.

using regular ‘sort’

Thank you in Advance.

  • 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-01T14:31:39+00:00Added an answer on June 1, 2026 at 2:31 pm
    import Data.Function (on)
    import Data.List (sortBy)
    
    results xs = sortBy (compare `on` fst) (frequency xs)
    
    -- or, if you prefer
    results xs = sort (frequency xs)
    

    Links to documentation for on, sortBy, compare, fst.

    The difference is that sort sorts in ascending order of the first element of each pair, breaking tie-breaks with the second elements of the pairs, while sortBy (compare `on` fst) explicitly only looks at the first element of each pair.

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

Sidebar

Related Questions

I have a function that I use quite frequently, which allows me to write
I have function getCartItems in cart.js and I want to call that function in
I have function Start() that is fired on ready. When I click on .ExampleClick
I have function some_func_1 which will create an object of type some_type and will
I have written a function which reads an input buffer of bytes and produces
I'm writing an audio program in Haskell using Portaudio. I have a function that
I have this Array i wrote a function MostFreq that takes an array of
We have an auto-complete list that's populated when an you send an email to
I have a list of amplitude frequency response points. The amplitudes are given in
I often have function such as: sin(a*w*t + p) where: w = natural frequency

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.