为 haskell 代码编写一个高阶函数

Write a Higher Order Function for haskell code

这里有一些 haskell 函数定义。

f1 (x:xs) (y:ys) = (x+y) : f1 xs ys
f1 _ _ = []
f2 (xs:xss) (ys:yss) = (xs++ys) : f2 xss yss
f2 _ _ = []
f3 (x:xs) (y:ys) = (x*y) : f3 xs ys
f3 _ _ = []
f4 (x:xs) (y:ys) = (x+42) : f4 xs ys
f4 _ _ = []
f5 (x:xs) (y:ys) = (y-x*x) : f5 xs ys
f5 _ _ = []

所以,我需要创建一个高阶函数 hof 来捕获这种常见行为,并重写上面的 f1、f2、f3、f4 和 f5 中的每一个,以调用 hof 适当的论据。最后,与前面部分无关的是Haskell Prelude(在另一个名字下)提供的hof?

hof f list1 list2 = zipWith f list1 list2

f1 list1 list2 = hof (+) list1 list2

f2 list1 list2 = hof (++) list1 list2

f3 list1 list2 = hof (*) list1 list2

f4 list1 list2 = hof func list1 list2
                where func x _ = x+42

f5 list1 list2 = hof func list1 list2
                where func x y = y - (x*x)