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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:38:20+00:00 2026-06-17T08:38:20+00:00

Will GHC transform an expression with intermediate values as efficiently as one without? e.g.

  • 0

Will GHC transform an expression with intermediate values as efficiently as one without?

e.g.

main = print $ f ["aa", "bb", "cc"]

f x = 
   let a = map (map toUpper) x
       b = filter (\z -> 'C' /= head z) a
       c = foldl1 (++) b
   in c

seems to have very different core output (with -ddump-simple) than with

f x = foldl1 (++) $ filter (\z -> 'C' /= head z) $ map (map toUpper) x

Could an expression with intermediate values take (significantly) longer to evaluate?

  • 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-17T08:38:21+00:00Added an answer on June 17, 2026 at 8:38 am

    Linear use of intermediate let bindings is equivalent to putting (.) between the values.

    GHC will fuse through such pipelines. You can see from the results of -ddump-simpl-stats

    With let Bindings:

    15 RuleFired
        1 ++
        1 Class op /=
        1 Class op show
        1 Class op showList
        1 filter
        1 fold/build
        1 foldr/app
        1 map
        1 neChar#->case
        3 unpack
        3 unpack-list
    

    Using a pipeline:

    15 RuleFired
        1 ++
        1 Class op /=
        1 Class op show
        1 Class op showList
        1 filter
        1 fold/build
        1 foldr/app
        1 map
        1 neChar#->case
        3 unpack
        3 unpack-list
    

    And the same fused worker:

    With let Bindings:

    Main.main_go =
      \ (ds_aAz :: [[GHC.Types.Char]]) ->
        case ds_aAz of _ {
          [] -> GHC.Types.[] @ [GHC.Types.Char];
          : y_aAE ys_aAF ->
            case GHC.Base.map
                   @ GHC.Types.Char @ GHC.Types.Char GHC.Unicode.toUpper y_aAE
            of wild1_azI {
              [] ->
                GHC.List.badHead
                `cast` (UnsafeCo (forall a_azK. a_azK) [[GHC.Types.Char]]
                        :: (forall a_azK. a_azK) ~ [[GHC.Types.Char]]);
              : x_azM ds1_azN ->
                case x_azM of _ { GHC.Types.C# c2_aAa ->
                case c2_aAa of _ {
                  __DEFAULT ->
                    GHC.Types.: @ [GHC.Types.Char] wild1_azI (Main.main_go ys_aAF);
                  'C' -> Main.main_go ys_aAF
                }
    

    Pipeline:

    Main.main_go =
      \ (ds_aAA :: [[GHC.Types.Char]]) ->
        case ds_aAA of _ {
          [] -> GHC.Types.[] @ [GHC.Types.Char];
          : y_aAF ys_aAG ->
            case GHC.Base.map
                   @ GHC.Types.Char @ GHC.Types.Char GHC.Unicode.toUpper y_aAF
            of wild1_azB {
              [] ->
                GHC.List.badHead
                `cast` (UnsafeCo (forall a_azD. a_azD) [[GHC.Types.Char]]
                        :: (forall a_azD. a_azD) ~ [[GHC.Types.Char]]);
              : x_azF ds1_azG ->
                case x_azF of _ { GHC.Types.C# c2_aA3 ->
                case c2_aA3 of _ {
                  __DEFAULT ->
                    GHC.Types.: @ [GHC.Types.Char] wild1_azB (Main.main_go ys_aAG);
                  'C' -> Main.main_go ys_aAG
                }
                }
    

    Did you forget to compile with -O2 ?

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

Sidebar

Related Questions

Will GHC perform tail-call optimization on the following function by default? The only weird
Will my windows-7, command prompt allow me to filter memory logcat messages for my
It's rather nice that ghc-pkg check will list broken packages, and why they are
Will the following code: while True: try: print(waiting for 10 seconds...) continue print(never show
Will the following code cause a ConcurrentModificationException or other side effects? ArrayList<String> newList =
Will a thread stop if I send it SIGTSTP signal? Or in other words
Will the events that I added to the global event bus deleted by calling
Will the element be visible even for a blink of an eye If it
Will the following media queries behave exactly same on mobile devices and computers or
Will Java 8 support pattern matching like Scala and other functional programs do? I'm

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.