我知道它很冗长,但这就是我学习语法的方式。这条线在
(abCombo' a 2 lst) ... 我想返回“列表”和/或打印列表,但我无法使用此返回类型“Writer [String] [Int]”提取列表。
-- Loop through several integer values
-- and calculate the power of a^b, append to list
abCombo' :: Int -> Int -> [Int] -> Writer [String] [Int]
abCombo' a b lst
| b == maxB = do
tell [ " ... x-Done(1): a^b = " ++ show (a^b) ++ " // " ++ show lst ]
return ((a^b):lst)
| otherwise = do
tell [ " ... x-Processing: a^b = " ++ show (a^b) ++ " // " ++ show lst ]
abCombo' a (b+1) ((a^b):lst)
-- Loop through several integer values
-- and calculate the power of a^b, append to list
abCombo :: Int -> [Int] -> Writer [String] [Int]
abCombo a lst
| a == maxA = do
tell [ "- Done(2): a=" ++ show a ]
abCombo' a 2 lst
| otherwise = do
(abCombo' a 2 lst) <<<<<<<<<<<<<<<<<<<<<< line of interest, here
tell ["- Processing: a=" ++ show a]
abCombo (a + 1) lst
...
也就是上面的当前代码,我想把它改成:
abCombo :: Int -> [Int] -> Writer [String] [Int]
abCombo a lst
| a == maxA = do
tell [ "- Done(2): a=" ++ show a ]
abCombo' a 2 lst
| otherwise = do
let res = (abCombo' a 2 lst) <<<<<<<<<<<<<<<<<<<<<< line of interest, here
tell ["- Processing: a=" ++ show a]
abCombo (a + 1) (flatten snd res)