-1
combinationIO :: Int -> [a] -> IO [[a]]
combinationIO 0 _ = return [[]]
combinationIO _ [] = return []
combinationIO n (x:xs) = do res <- (map (x:) (combinationIO (n-1) xs)) ++ (combinationIO n xs)
putStrLn $ (show n) ++ show " : (" ++ show (x,xs) ++ show ") = " ++ show res
return res
일부 사이트에서이 예제 (아래)를 보았고 작동하는 방식이 궁금해서이 작업에 IO 작업을 넣었습니다. 그러나 ghci는 나에게 유형 오류를줍니다. 문제가 무엇입니까?하스켈 - 왜 작동하지 않습니까? (IO 작업 wth 목록)
combination2 :: Int -> [a] -> [[a]]
combination2 0 _ = [[]]
combination2 _ [] = []
combination2 n (x:xs) = (map (x:) (combination2 (n-1) xs)) ++ (combination2 n xs)
무엇이 오류입니까? – chepner
코드를 정확히 여기에 넣은 경우, 들여 쓰기 문제가 있습니다.'putStrLn'과'return'은'res <--'가 시작되는 레벨에서 정확하게 들여 쓰기되어야합니다. – Tarmil