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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:20:11+00:00 2026-05-21T11:20:11+00:00

(unimportant background info / motivation) I was implementing a different version of nub ,

  • 0

(unimportant background info / motivation)

I was implementing a different version of nub, inspired by the Yesod book’s discouragement of using it.

map head . group . sort is more efficient than a call to nub. However, in our case, order is important…

So I set out writing a “better” nub akin to the order-unimportant version. And I ended up with this:

mynub = unsort . map head . groupBy (\x y -> fst x == fst y) . sortBy (comparing fst) . rememberPosition

rememberPosition = flip zip [0..]
unsort = map fst . sortBy (comparing snd)

This certainly does a lot of extra work, but it should be O(n log n) instead of original nub’s O(n2). But that’s beside the point. The problem is, it’s so long! It’s really not that complicated, but it’s long (and I’m one of those people that hates going wider than 80 columns, or horizontal scrollbars on StackOverflow code blocks).

(the question)

What are better ways in Haskell for expressing long chains of function composition such as this?

  • 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-21T11:20:12+00:00Added an answer on May 21, 2026 at 11:20 am

    Break up the line, and use the layout:

    mynub = unsort 
          . map head 
          . groupBy ((==) `on` fst)
          . sortBy (comparing fst) 
          . rememberPosition
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Semi-unimportant background: I'm working on a page with two sets of collapsable panels. (using
Another unimportant performance question. Unimportant because mostly code-readability is much more important than a
I have a website project that has more than 50,000 unimportant files (to development)
Ok, this question is for people with either a deep knowledge of PRISM or
In the next few weeks, my company will be engaging multiple vendors to establish
I have an application that grabs a snapshot of another desktop. This process is
I'll be writing a validator for a specific file format (the format itself is
I've seen this in a few pieces of code and I didn't want to
I am looking for an alternative to the visitor pattern. Let me just focus
I'm looking form a programatic way to take an integer sequence and spit out

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.