I have a problem with implementing the FP (Backus) interpreter in Haskell.
FP functions are as follows:
[+,*]:<2,3>
should appear with
<+:<2,3>, *:<2,3>> -> <5,6>
means that each function from the list on the left should be executed for each element of the list on the right.
I understand that I need something similar to the "map" function, but the map uses one function in the list, and I need a list of functions in the list of values.
Thank you in advance!: -)
EDIT:
Since I was not accurate, here is my code that does not work:
apply :: [String] -> [Integer] -> [Integer] apply fs v = [((apply_f fx) | f <- fs | x <- v)] apply_f :: String -> [Integer] -> [Integer] apply_f "+" v = [(sum v)] apply_f "*" v = [(product v)]
I canβt understand why ...: - (
EDIT 2:
Sorry, I'm too tired of working all day on this. The problem is that I do not need a second pipe, only the first:
apply fs v = [ apply_f fv | f <- fs ]
Now everything works fine, thank you very much !:-)
markoub
source share