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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:14:43+00:00 2026-05-26T00:14:43+00:00

this is what I have for matrix addition in Haskell > add :: (Num

  • 0

this is what I have for matrix addition in Haskell


    > add :: (Num a) => [[a]] -> [[a]] -> [[a]]
    > add [] [] = [] 
    > add (x:xs) (y:ys) = zipWith (+) x y : add xs ys

add [[1,2], [3,4]] [[5,6], [7,8]] gives me [[6,8],[10,12]]

However, I am trying do with one line instead


    > add :: (Num a) => [[a]] -> [[a]] -> [[a]]
    > add = map ((zipWith (+))

How come the map function doesn’t work?

  • 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-26T00:14:44+00:00Added an answer on May 26, 2026 at 12:14 am

    The map function doesn’t work here because you’re iterating over two lists instead of one. To iterate over two lists in parallel, you use zipWith, just like you are already doing for the inner loop.

    Prelude> let add = zipWith (zipWith (+))
    Prelude> add [[1, 2], [3, 4]] [[5, 6], [7, 8]]
    [[6,8],[10,12]]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have this: A * f = g; A: upper triangular matrix (n
I have a function like this: MyFunction(double matrix[4][4]) {/*do stuff*/} I am calling this
I have this line in a javascript block in a page: res = foo('<%=
There are many articles in this site regarding my question. I have a matrix
I have this: using namespace boost::numeric::ublas; matrix<double> m (3, 2); int k = 0;
This is an OpenCV2 question. I have a matrix representing a closed space curve.
I have this matrix A, representing similarities of pixel intensities of an image. For
As a simple example, let's say you have this matrix: M = [omega 1;
I have matrix with 3 dimension (n*m*k). I am trying to fined the maximum
let's say I have a matrix (array) like this example, but much larger: 0

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.