Using an element against an entire list in Haskell

Posted by Snick on Stack Overflow See other posts from Stack Overflow or by Snick
Published on 2010-05-13T07:26:54Z Indexed on 2010/05/13 7:34 UTC
Read the original article Hit count: 238

I have an assignment and am currently caught in one section of what I'm trying to do. Without going in to specific detail here is the basic layout: I'm given a data element, f, that holds four different types inside (each with their own purpose):

data F = F Float Int, Int

a function:

func :: F -> F-> Q  

Which takes two data elements and (by simple calculations) returns a type that is now an updated version of one of the types in the first f.

I now have an entire list of these elements and need to run the given function using one data element and return the type's value (not the data element). My first analysis was to use a foldl function:

myfunc :: F -> [F] -> Q
myfunc y [] = func y y -- func deals with the same data element calls
myfunc y (x:xs) = foldl func y (x:xs)

however I keep getting the same error:

"Couldn't match expected type 'F' against inferred type 'Q'. 
In the first argument of 'foldl', namely 'myfunc'
In the expression: foldl func y (x:xs)

I apologise for such an abstract analysis on my problem but could anyone give me an idea as to what I should do? Should I even use a fold function or is there recursion I'm not thinking about?

© Stack Overflow or respective owner

Related posts about haskell

Related posts about function