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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:29:45+00:00 2026-05-29T22:29:45+00:00

Trying to implement a function that will return a list of ints the represent

  • 0

Trying to implement a function that will return a list of ints the represent an ordering of each list of doubles, e.g.:

orderings [ [1.0, 2.0, 3.0], [3.0, 2.0, 1.0] ]
> [ [0, 1, 2], [2, 1, 0] ]

However, having trouble with my pattern matching for some reason:

import Data.List

-- Return a list of orderings for each list of doubles
orderings:: [[Double]] -> [Int]
orderings [] = []
orderings x:xs = (ordering x):(orderings xs)

ordering:: [Double] -> [Int]
ordering xs = [i | (i, _) <- sorted] where
    sorted = sortBy (\(i1, e1) (i2,e2) -> compare e1 e2) $ zip [0..] xs

Error is:

Parse error in pattern: orderings

Can’t see the error for the life of me!

  • 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-29T22:29:47+00:00Added an answer on May 29, 2026 at 10:29 pm

    Two more problems (in addition to the missing parentheses around x:xs):

    1. the type of orderings is wrong; I suspect it should be [[Double]] -> [[Int]]

    2. x is not in scope in ordering; I suspect it should be xs

    Here’s the corrected code:

    import Data.List
    
    -- Return a list of orderings for each list of doubles
    orderings:: [[Double]] -> [[Int]]  -- changed type
    orderings [] = []
    orderings (x:xs) = (ordering x):(orderings xs)
    
    ordering:: [Double] -> [Int]
    ordering xs = [i | (i, _) <- sorted] where
        sorted = sortBy (\(i1, e1) (i2,e2) -> compare e1 e2) $ zip [0..] xs -- xs not x!
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to implement a function in my linkedlist class that will return total amount
I'm trying to implement a function that have to return the minimum value from
I am trying to implement a function that will insert a new entry in
I'm trying to implement an ActionMailer function that will send out a newsletter to
I'm trying to implement the following functionality; a function with no explicit return will
I am trying to implement a function that will check to see if a
I am trying to implement a function for my SSRS report which will return
I'm trying to implement unit tests for function that uses imported external objects. For
I'm trying to implement a unit test for a function in a project that
I’m trying to implement a tail-recursive list-sorting function in OCaml, and I’ve come up

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.