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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:22:47+00:00 2026-05-27T21:22:47+00:00

I was writing a quick one-liner in GHCi and tried to compose sum with

  • 0

I was writing a quick one-liner in GHCi and tried to compose sum with map. I figured the reason it failed is because map gives output of a general type [b] whereas sum takes in specific input Num a => [a]. However, there is nothing wrong with this code assuming that the output of the map function is type Num b => [b].

I thought writing a restricting type declaration might work (although I guess that prevents you from doing it in GHCi) but it still didn’t:

myFunc :: Num b => (a -> b) -> [a] -> b
myFunc = sum . map

Gave me the following error:

Couldn't match expected type `[[a] -> b]'
            with actual type `[a] -> [b]'
Expected type: (a -> b) -> [[a] -> b]
  Actual type: (a -> b) -> [a] -> [b]
In the second argument of `(.)', namely `map'
In the expression: sum . map

Is there any way to do this? Maybe I am just missing something obvious (new to Haskell).

  • 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-27T21:22:47+00:00Added an answer on May 27, 2026 at 9:22 pm

    sum . map isn’t a definition you’re looking for. Observe that

     (.) :: (b -> c) -> (a -> b) -> a -> c
    

    The dot operator accepts two unary functions. It doesn’t work as map takes two arguments:

    map :: (a -> b) -> [a] -> [b]
    

    One of possible solutions would be to explicitly bind map‘s first argument:

    myFunc :: Num c => (a -> c) -> [a] -> c
    myFucc f = sum . map f
    

    Alternatively you could use curry and uncurry and achieve the same result.

    myFunc = curry $ sum . uncurry map
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a simple program to convert text to strings. One quick question, how
Hopefully this is a quick one, and Easy if you know how... I'm writing
Just a quick one - I'm in the process of writing a Sega Master
I'm writing a quick plugin (one of my first) to help with buttons if
Quick background: writing a module. One of my objects has methods that may or
Here's a quick one. I'm trying to get better at writing selectors for jquery
I'm writing a quick one-off migration script that updates a single field in a
I'm writing a quick one-off web application for a friend using Rails 3.0.9. It's
All, quick and easy one here... I'm writing an Evaluate function that runs through
I'm currently writing a quick solution for Euler Problem #4 where one must find

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.