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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:28:30+00:00 2026-06-11T08:28:30+00:00

What are the performance benefits of using ~ (lazy pattern matching) in Data.List’s partition.

  • 0

What are the performance benefits of using ~ (lazy pattern matching) in Data.List’s partition. Contrived examples of lazy pattern matching suggest that it is useful when the values inside the tuple constructor are never used (f (x,y) = 1). In partition (select, below), the lists ts, fs are always used (if the predicate p applied to x is True, or not). I’m sure this is a very well informed decision to use ~, but what is the point? Why not strict pattern matching?

partition               :: (a -> Bool) -> [a] -> ([a],[a])
{-# INLINE partition #-}
partition p xs = foldr (select p) ([],[]) xs

select :: (a -> Bool) -> a -> ([a], [a]) -> ([a], [a])
select p x ~(ts,fs) | p x       = (x:ts,fs)
                    | otherwise = (ts, x:fs)

(Note: I’ve already looked here! it doesn’t answer the above question)

  • 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-11T08:28:31+00:00Added an answer on June 11, 2026 at 8:28 am

    The point is that with strict pattern matching, assembling of the result could only start when the end of the list to be partitioned has been reached, in particular, partition would not work at all for infinite lists.

    With a strict pattern match, the argument must be evaluated to WHNF. That means the entire foldr of the tail must have finished before it is decided whether x is put in the first or the second component.

    select p x (foldr (select p) ([],[]) (y:z:ws))
    ~> select p x (select p y (select p z (foldr (select p) ([],[]) ws)))
    

    With a lazy pattern match, a pair is constructed immediately, with x as the first element of the appropriate component, and the rest of the two lists to be evaluated later, when needed.

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

Sidebar

Related Questions

Of what I know of benefits of using initialization list is that they provide
Is there any performance benefits to using Command objects to validate constraints over using
I've read that javascript gets significant performance benefits from modifying off-dom. Earlier today, I
Are there any performance benefits to me not using the gridview in asp.net for
Are there ever any performance (speed & memory) benefits to using a properly-implemented singleton
I'm curious as to the performance benefits of using hasEventListener() over blindly dispatching an
Is there any performance benefits of using static typing in Objective-C? Does it exist
What are the performance benefits or penalties of using goto with a modern C++
I realize you get more customization but are there performance (mem/speed) benefits to using
Switching from JVM 1.4 to 1.5 has performance benefits as per release notes. http://java.sun.com/j2se/1.5.0/docs/relnotes/features.html#performance

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.