如何定义 listTree 使其 returns 一个包含所有元素的列表?

How to define listTree so that it returns a list containing all the elements in order?

listTree :: Tree a -> [a]
listTree = foldTree f z
    where
    f x y z  = x + y + z
    z = []

这是我目前所拥有的,但是我的 f 是错误的,因为预期类型是 Tree a -> [a] 但实际是 Tree [a] -> [a]

data Tree a
   = Tip
   | Bin (Tree a) a (Tree a)
   deriving (Show, Eq)

foldTree :: (b -> a -> b -> b) -> b -> Tree a -> b
foldTree f z Tip         = z
foldTree f z (Bin l x r) = f (foldTree f z l) x (foldTree f z r)

这是树的折叠和数据类型。

需要帮助定义 f

首先,组合列表在haskell中使用+++ 仅用于数字相加。其次,变量y的类型是a,不是[a],所以不能直接对它使用++

listTree :: Tree a -> [a]
listTree = foldTree f z
    where
    f x y z = x ++ [y] ++ z
    z = []