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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:21:36+00:00 2026-06-12T01:21:36+00:00

I have three functions ( getRow , getColumn , getBlock ) with two arguments

  • 0

I have three functions (getRow,getColumn,getBlock) with two arguments (x and y) that each produce a list of the same type. I want to write a fourth function that concatenates their outputs:

outputList :: Int -> Int -> [Maybe Int]
outputList x y = concat . map ($ y) $ map ($ x) [getRow,getColumn,getBlock]

The function works, but is there a way to rewrite the double map (with three ‘$’s) to a single map?

  • 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-12T01:21:37+00:00Added an answer on June 12, 2026 at 1:21 am
    import Data.Monoid
    
    outputList :: Int -> Int -> [Maybe Int]
    outputList = mconcat [getRow, getColumn, getBlock]
    

    You deserve an explanation.

    First, I’ll explicitly note that all these functions have the same type.

    outputList, getRow, getColumn, getBlock :: Int -> Int -> [Maybe Int]
    

    Now let’s start with your original definition.

    outputList x y = concat . map ($ y) $ map ($ x) [getRow,getColumn,getBlock]
    

    These functions result in a [Maybe Int], and a list of anything is a monoid. Monoidally combining lists is the same as concatenating the lists, so we can replace concat with mconcat.

    outputList x y = mconcat . map ($ y) $ map ($ x) [getRow,getColumn,getBlock]
    

    Another thing that’s a monoid is a function, if its result is a monoid. That is, if b is a monoid, then a -> b is a monoid as well. Monoidally combining functions is the same as calling the functions with the same parameter, then monoidally combining the results.

    So we can simplify to

    outputList x = mconcat $ map ($ x) [getRow,getColumn,getBlock]
    

    And then again to

    outputList = mconcat [getRow,getColumn,getBlock]
    

    We’re done!


    The Typeclassopedia has a section about monoids, although in this case I’m not sure it adds that much beyond the documentation for Data.Monoid.

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

Sidebar

Related Questions

I have three functions that find the nth element of a list: nthElement ::
I have three functions in spherical coordinates that I want to plot. They are
I have three functions, that each one of them calls internally the one below
I have a simple JavaScript file that has three jQuery $document.ready functions. All three
If we have three functions (foo, bar, and baz) that are composed like so...
I have written three different Private Sub functions, all of which do the same
I have three functions that ought to be equal: let add1 x = x
I have three custom functions that do very similar things: they pull different data
I have these three functions inside the same class: public function checkLogin() { if(isset($this->getSessionVal()))
I have three functions that return integer error codes, e.g. int my_function_1(const int my_int_param);

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.