List 使用CombinationsGeneration.combinations返回的Haskell打印整数列表

List 使用CombinationsGeneration.combinations返回的Haskell打印整数列表,list,haskell,printing,List,Haskell,Printing,我已经在网上搜索过了,我有真实世界的Haskell,但我不知道当CombinationsGeneration.combinations返回整数列表时,如何打印整数列表 我发现函数处的模块没有类型签名,因此Haskell必须推断所有内容。我甚至尝试添加签名,但错误仍然存在(更具体的一个) 我在该模块中使用的源代码是: combinationsOf 0 _ = [[]] combinationsOf _ [] = [] combinationsOf k (x:xs) = map (x:) (comb

我已经在网上搜索过了,我有真实世界的Haskell,但我不知道当CombinationsGeneration.combinations返回整数列表时,如何打印整数列表

我发现函数处的模块没有类型签名,因此Haskell必须推断所有内容。我甚至尝试添加签名,但错误仍然存在(更具体的一个)

我在该模块中使用的源代码是:

combinationsOf 0 _ = [[]]
combinationsOf _ [] = []
combinationsOf k (x:xs) = map (x:) (combinationsOf (k-1) xs)
                          ++ combinationsOf k xs

combinations k n = combinationsOf k [1..n]
我添加了以下签名,以查看这是否有区别,但没有:

combinationsOf :: Integer -> [a] -> [[a]]
combinations :: Integer -> Integer -> [[Integer]]
我的Haskell源文件是:

module Main
    where
        import IO
        import qualified CombinatoricsGeneration as CG

        main = putStr $ unlines $ map show CG.combinations(6, 8)
CombinaticsGeneration的编译是可以的。但我的一个源文件产生了一个错误:

$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 6.12.3
$ ghc -c CombinatoricsGeneration.hs 
$ ghc -o test  CombinatoricsGeneration.o test.hs 

test.hs:6:37:
Couldn't match expected type `[a]'
       against inferred type `t -> t1 -> [[t1]]'
In the second argument of `map', namely `CG.combinations'
In the second argument of `($)', namely
    `map show CG.combinations (6, 8)'
In the second argument of `($)', namely
    `unlines $ map show CG.combinations (6, 8)'
但是,以下行可以正常工作:

main = putStr $ unlines $ map show [[1,2],[2],[3]]
你能帮我显示那个简单的列表吗


TIA

您错误地调用了函数
(6,8)
是一个元组
(Num a1,Num a2)=>(a1,a2)
,所以

CG.combinations(6, 8)
实际上需要签名
CG.compositions
as

(Num a1, Num a2) => (a1, a2) -> b
而不是
a1->a2->b

由于
map show
将应用于函数
CG.compositions
,而不是
CG.compositions(6,8)
的结果,因此优先级也存在问题

您应该按如下方式调用该函数

putStr $ unlines $ map show (CG.combinations 6 8)
-- #                        ^^^^^^^^^^^^^^^^^^^^^