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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:35:34+00:00 2026-05-24T22:35:34+00:00

I have to write a Haskell program that does the following: Main> dotProduct [(1,3),(2,5),(3,3)]

  • 0

I have to write a Haskell program that does the following:

Main> dotProduct [(1,3),(2,5),(3,3)]  2
[(2,3),(4,5),(6,3)]

I have to do it both with and without map function.
I already did it without map, but I have no clue to do it with map.

My dotProduct without map function:

dotProduct :: [(Float, Integer)] -> Float -> [(Float, Integer)]
dotProduct [] _ = []
dotProduct [(x,y)] z = [(x*z,y)]
dotProduct ((x,y):xys) z = (x*z,y):dotProduct (xys) z

So I really need help with the map version.

  • 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-24T22:35:34+00:00Added an answer on May 24, 2026 at 10:35 pm

    EEVIAC already posted the answer, so I’ll just explain how to come up with it yourself. As you probably know, map has the type signature (a -> b) -> [a] -> [b]. Now, dotProduct has the type [(Float, Integer)] -> Float -> [(Float, Integer)] and you’ll call map somewhere in there, so it has to look something like this:

    dotProduct theList z = map (??? z) theList
    

    where ??? is a function of type Float -> (Float, Integer) -> (Float, Integer) – this follows immediately from the type signature of map and from the fact that we pass z to the function, which we have to do, simply because there’s no other place to use it in.

    The thing with map and higher order functions in general is that you have to keep in mind what the higher order function does and “simply” supply it with the correct function. As map applies a given function to all elements in the list, your function only needs to work with one element, and you can forget all about the list – map will take care of it.

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

Sidebar

Related Questions

The debug screen says that django does not have write access to the db.
I'm trying to write a Haskell append function... Here's what I have: myappend ::
I'm trying to write a haskell function that takes in two lists of integers
I'm currently working with Java to write a program that does an EAI between
I am new at haskell, I have to write a program context-aware,so I thought
I'm writing a simple web app in PHP that needs to have write access
I have to write an applet that brings up a password dialog. The problem
I have to write something in vbscript that need to use a unique set.
I have to write a component that re-creates SQL Server tables (structure and data)
I'm developing a small haskell program that uses an external static library I've developed

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.