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

The Archive Base Latest Questions

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

Those are my first explorations in Haskell, so pardon me if it should be

  • 0

Those are my first explorations in Haskell, so pardon me if it should be obvious.

I have been playing all afternoon with Haskell, sifting through the tutorial 99 questions on HaskellWiki, using my own list type (typical Cons). I’ve added “obvious” functions as I went on, and I have tried to make them as concise as possible (employing point-free notation whenever possible)

The 12th problem is about decoding a run-length encoded list, that is:

> decode [Multiple 5 'a', Single 'b', Multiple 2 'c']
"aaaaabcc"

And I thought about using map to decode each element, then concat the result (thanks Google on this), and finally remembered that I had seen something like concatMap in my readings, which GHCi quickly confirmed:

> :t map
map :: (a -> b) -> [a] -> [b]
> :t concat
concat :: [[a]] -> [a]
> :t concatMap
concatMap :: (a -> [b]) -> [a] -> [b]

It looked like it would be obvious to reimplement concatMap:

concatMap :: (a -> [b]) -> [a] -> [b]
concatMap = concat . map

Except that GHCi quite complains:

List.hs:110:15:
    Couldn't match expected type `[a] -> [b]'
                with actual type `[a0]'
    Expected type: [[a0]] -> [a] -> [b]
      Actual type: [[a0]] -> [[a0]]
    In the first argument of `(.)', namely `concat'
    In the expression: concat . map

I could not figure it out, so I looked up on the web, and the definition referenced in Prelude is actually:

concatMap f = concat . map f

And I don’t quite understand why this f is necessary, since it’s type is obviously a -> [b] as specified by the signature…

So why is f necessary here ?

  • 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-20T23:11:14+00:00Added an answer on May 20, 2026 at 11:11 pm

    Starting with the standard definition,

    concat . map f 
     ≡ concat . (map f)
     ≡ \x -> concat ((map f) x)
    

    Your first definition gives you:

    (concat . map) f
     ≡ (\x -> concat (map x)) f
     ≡ concat (map f)
    

    which doesn’t type check because (map f) :: [a] -> [b], while concat takes [[a]], a list of lists.

    Note the particular error message shown in the question doesn’t describe the above type-check failure. The given message arises from declaring the return type concatMap as [a] -> [b], which isn’t reconcilable with [a0], the return type of concat. If you leave off the type signature, the response is:

        Couldn't match type ‘[a1] -> [b]’ with ‘[[a]]’
        Expected type: (a1 -> b) -> [[a]]
          Actual type: (a1 -> b) -> [a1] -> [b]
        Relevant bindings include
          concatMap :: (a1 -> b) -> [a] (bound at :49:5)
        Probable cause: ‘map’ is applied to too few arguments
        In the second argument of ‘(.)’, namely ‘map’
        In the expression: concat . map
    

    Here, the type error occurs when reconciling the return type of map with the argument type of concat. It turns out this case is more useful for debugging as it contains a hint why the type check failed.

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

Sidebar

Related Questions

I have a folder with these files: alongfilename1.txt <--- created first alongfilename3.txt <--- created
For those who like a good WPF binding challenge: I have a nearly functional
For those of you who have implemented Scrum in your organizations, what were your
First of all, it's great. However, I came across a situation where my benchmarks
this is my first time with nginx rewrite, who can help me convert those
It seems, at the first glass, that we can use either of those. I'm
We use liquibase to keep track of our database changes.. First changeSet contains those
I'm querying the database first to get all records associated with a certain userid,
First shot at throwing a question on these boards so hopefully I can get
Those of us with iPhone apps (released or unreleased) are able to send 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.