Reputation: 43
Supposedly I have those functions of the same type and result in Haskell:
add_one :: Integer -> Integer
add_one n = n + 1
multiply_by_five :: Integer -> Integer
multiply_by_five n = n * 5
subtract_four :: Integer -> Integer
subtract_four n = n - 4
add_ten :: Integer -> Integer
add_ten n = n + 10
How can I make a list from them so I can apply it to one single argument of Integer type such as:
map ($ single_argument) list_of_functions
?
Upvotes: 4
Views: 358
Reputation: 367
Constructing lists with Haskel is done by using the (:) and [] list constructors, like so:
fList :: [Integer -> Integer]
fList = add_one : multiply_by_five : subtract_four : add_ten : []
-- or by using some syntactic sugar
fList' = [add_one, multiply_by_five, subtract_four, add_ten]
You can then indeed map application:
map ($ 3) fList
Upvotes: 10