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
?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With