haskell - haskell使用map調用有多個參數的函數

假設有以下代碼,表示二進位樹,其中decodeInt在樹上搜索整數:


import Text.Show.Functions


data BinTree a b = Leaf b | Node a (BinTree a b) (BinTree a b) deriving Show



example :: BinTree (Int -> Bool) Char


example = Node (x -> x > 4) (Node (x -> x * x == x) (Leaf 'g') (Node (x -> x == 0)


 (Leaf 'u') (Leaf 'l'))) (Node (x -> x >= 7) (Leaf 'f') (Leaf 'i'))



countInnerNodes :: BinTree a b -> Int


countInnerNodes (Node a b c) = 1 + countInnerNodes b + countInnerNodes c


countInnerNodes (Leaf x) = 0



decodeInt :: BinTree (Int -> Bool) b -> Int -> b


decodeInt (Leaf b) p = b


decodeInt (Node x y z) p = if (x(p) == True) then decodeInt z p else decodeInt y p



decode :: BinTree (Int -> Bool) b -> [Int] -> String


decode x [] ="empty list"


decode x xs = ??????



調用decode時,如何使用map獲取這樣的結果?


decode Tree [1,2,3,4] 


 = [decodeInt Tree (1), decodeInt Tree (2), 


 decodeInt Tree (3), decodeInt Tree (4)]



时间: 原作者:

decodeInt :: BinTree (Int -> Bool) b -> Int -> b那麼假設t :: BinTree (Int -> Bool) b那就decodeInt t :: Int -> b將該函數映射到Int s列表上。


decode t xs = let y = map (decodeInt t) xs


 in ...



原作者:
...