haskell - Apply a function to a list of items -


I have defined a function f which will be given value Item is x stored inside a list of prices with [code] [[string, string, ante]]

  a = string x = String value = int prices list = [(a, x, price)] fax ((a1, x1, price): ys). A == A1 & amp; Amp; X == x1 = value | Otherwise = FA x YS   

I have to apply this function in a list of items, but I'm stuck. Is it possible to use the map? I can not get it.

(Only functions that can use recursion f)

Edit to clarify some examples

 < Code> pricesList = [("Apple", "iPod", 100), ("Apple", "iPhone", 200), ("Samsung", "Galaxy", 200)] Passure = [("Harry", 1 9 85, "Apple", ["iPhone", "iPod"]), ("George", 1983, "Samsung", ["Galaxy"])] * Main & gt;   

I should know how much money has been spent by defining a new function, assuming that spent code> F Inside of it)

  * main & gt; "Its what's up to now"  
  itsThePerson name (n, _, _, _) = name == n InfoFrom name = (head filter (its peers name)) Money brand (_ , _, B, _) = B product (_, _, _, P) = P brand = brand = brand InfoPerson = info from the product infoFrom   

Is it possible to use map with f to know the sum of the prices?

(function f will be itemprice )

  spent name = sum (map (itemprice (branding Name of the Xxx Prices List (Name of the Product)   

Am I thinking about it in the right direction?

Assume that you have three logic functions:

  f :: a -> gt - b -> c -> D   

and c list of values ​​- list :: [b] . Suppose that we have each f < / Code> want to apply list Item with default and first arguments, so we can do something like this:

  map (fxy) list   

where x :: a and y :: b .

In your case the only difference is the sequence of arguments. For such issues, flip :

  flip :: (a -> - - C) -> (b -> - - C) - basic function F :: a - & gt; be - & gt; C -> D - Particle Application Fx :: B - & gt; C -> D Flip Flip (FX) :: C -> B - & gt; D - Particle application again (Flip (FX) y) :: B - & gt; d map (flip (fx) y) list :: [D]   

In your case this will probably give some results in the map (flip (FA) prices .

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -