Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Haskell help, anyone?

Status
Not open for further replies.

trint

Technical User
Aug 23, 2002
4
0
0
GB
Hi All,

Although not prolog based. I'm trying to write a function in Haskell 'prod lst1 lst2' which sums the products of corresponding elements of two lists. e.g

prod [1,2,3] [4,5,6] = 1*4 + 2*5 + 3*6 =32

I'm think the 'map' function is to be used but i dont know how to implement the function. Any help on this will be greatfully appreciated.

Cheers,
Trint
 
prod :: [Int] -> [Int] -> Int
prod [] [] = 0
prod (x:xs) (y:ys) = (x*y) + prod xs ys
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top