私はそれが冗長であることを知っていますが、それが私が構文を学んでいる方法です。この行で
(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)