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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:22:19+00:00 2026-05-28T02:22:19+00:00

Can we put functions to determine the condition for our list comprehensions. Here is

  • 0

Can we put functions to determine the condition for our list comprehensions. Here is my code that I am trying to implement:

mQsort :: [String] -> [F.Record] -> [F.Record]
mQsort [] _ = []
mQsort c@(col:cond:cs) l@(x:xs) = (mQsort c small) ++ mid ++ (mQsort c large)
   where
    small = [y | y<-xs, (qGetStr col y) (qGetCond cond) (qGetStr col x)]
    mid   = mQsort cs [y | y<-l, (qGetStr col y) == (qGetStr col x)]
    large = [y | y<-xs, (qGetStr col y) (qGetCond' cond) (qGetStr col x)]

qGetStr :: String -> F.Record -> String
qGetStr col r | U.isClub col = F.club r
            | U.isMap col = F.mapName r
            | U.isTown col = F.nearestTown r
            | U.isTerrain col = F.terrain r
            | U.isGrade col =F.mapGrade r
            | U.isSW col = F.gridRefOfSWCorner r
            | U.isNE col = F.gridRefOfNECorner r
            | U.isCompleted col = F.expectedCompletionDate r
            | U.isSize col = F.sizeSqKm r
            | otherwise = ""

qGetCond "ascending" = (<)
qGetCond "decending" = (>)
qGetCond' "ascending" = (>)
qGetCond' "decending" = (<)

I get an error stating that the function qGetStr is applied to 4 arguments instead of 2.
Also, qGetCond – is this the right syntax to return an operator. I had to place the operator in brackets due to a compile error, but I have a feeling this is incorrect

  • 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-28T02:22:20+00:00Added an answer on May 28, 2026 at 2:22 am

    Replace

    small = [y | y<-xs, (qGetStr col y) (qGetCond cond) (qGetStr col x)]
    

    with

    small = [y | y<-xs, (qGetCond cond) (qGetStr col y) (qGetStr col x)]
    

    Similarly for large.

    The reason is the same as the reason for the syntax you use to return an operator in qGetCond. An operator is just a function really.

    • foo < bar is the same as (<) foo bar
    • foo `fire` bar is the same as fire foo bar

    So you have to move the “operator” to the start of the expression in your list comprehension. (n.b. this is true in general and has nothing to do with list comprehensions in particular.)

    Edit: to expand on Chris Kuklewicz’s point:

    • Backticks only work around a single identifier. So foo `fire` bar is valid syntax, but something more complicated like foo `fire forcefully` bar or foo `(fire forcefully)` bar is a syntax error.

    • Parentheses round operators are more flexible. These expressions all evaluate to the same value:

      • foo < bar
      • (<) foo bar
      • (foo <) bar
      • (< bar) foo

      The last two forms are called operator sections. They are useful when passing a function to another function, e.g. map (+1) listOfIntegers. There are a couple of subtleties with the syntax:

      (quux foo <)      -- function calls are fine
      (baz + foo <)     -- syntax error because of the extra operator...
      ((baz + foo) <)   -- ...but this is ok
      (-3)              -- `-` is a special case: this is a numeric literal,
                        --                        not a function that subtracts three
      (subtract 3)      -- is a function that subtracts three
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two functions that i'm hoping i can put into one and can
You can't put two __construct functions with unique argument signatures in a PHP class.
I know I can put escaped HTML tags in string resources. However, looking at
With VIM or Emacs I can put comments in the file that will be
I'm trying to understand when I can put certain objects into a users session
Here is the way I can put float value to the stack(in C#): ILGenerator
What is TLV? To put hooks (functions) in the code instead of if/else? If
In some of my code I put a series of objects in a list
how i can put multiple buttons in scroll view with according to my requirement?
In C++ you can put a member in a base class and a member

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.