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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:50:35+00:00 2026-05-31T23:50:35+00:00

I’m trying to sort a list and to check my sorting algorithm is working

  • 0

I’m trying to sort a list and to check my sorting algorithm is working as I would expect I would like to print out specific elements of the sorted list, something I would expect to be a simple task but is proving to be very difficult – I guess I’m going about it the wrong way.

data Candidate = Candidate Float Float Float String

…

getName :: Candidate -> String
getName (Candidate weight profit effic name) = name

…

main = do
    let items = [Candidate 0.20 4.17 (calculateEfficiency 0.20 4.17) "Weapon"]
    Candidate 3.11 4.53 (calculateEfficiency 3.11 4.53) "Tinned food":items
    Candidate 1.04 4.64 (calculateEfficiency 1.04 4.64) "Ammunition":items
    Candidate 2.70 1.19 (calculateEfficiency 2.70 1.19) "Water":items   

    let sortedItems = sortBy mySort items
    putStrLn (getName (sortedItems !! 0))

The error I get is:

Couldn't match expected type `[b0]' with actual type `IO ()'
In the return type of a call of `putStrLn'
In the expression: putStrLn (getName (sortedItems !! 0))
In the expression:
  do { let items = ...;
         Candidate 3.11 4.53 (calculateEfficiency 3.11 4.53) "Tinned food"
       : items;
         Candidate 1.04 4.64 (calculateEfficiency 1.04 4.64) "Ammunition"
       : items;
         Candidate 2.7 1.19 (calculateEfficiency 2.7 1.19) "Water" : items;
       .... }
Failed, modules loaded: none.

Thanks for any help.

  • 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-31T23:50:37+00:00Added an answer on May 31, 2026 at 11:50 pm

    The : operator is the prepend operator for lists, but it doesn’t actually modify a list. Imagine that instead of a list, you had a number; what you are doing is equivalent to this:

    let items = 1
    2 + items
    7 + items
    3 + items
    

    That does’t make any sense.

    You need to store the result of the prepend somewhere. You can do this by either creating new variables for each step:

    let items = [Candidate 0.20 4.17 (calculateEfficiency 0.20 4.17) "Weapon"]
    let items2 = Candidate 3.11 4.53 (calculateEfficiency 3.11 4.53) "Tinned food" : items
    

    …or you can simply create a long list to begin with:

    let items = [ Candidate 0.20 4.17 (calculateEfficiency 0.20 4.17) "Weapon"
                , Candidate 3.11 4.53 (calculateEfficiency 3.11 4.53) "Tinned food"
                , Candidate 1.04 4.64 (calculateEfficiency 1.04 4.64) "Ammunition"
                ]
    

    This should yield the expected results, depending on if you also implemented mySort correctly.

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

Sidebar

Related Questions

I would like to count the length of a string with PHP. The string
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace

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.