Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Haskell,将字符串转换为所有可能的;“元组”;本身_Haskell_Tuples_Combinations - Fatal编程技术网

Haskell,将字符串转换为所有可能的;“元组”;本身

Haskell,将字符串转换为所有可能的;“元组”;本身,haskell,tuples,combinations,Haskell,Tuples,Combinations,我已经搜索并找到了一些解决方案,但没有一个像我所想的那么简单,因此您有一个数字列表[1,2,3,4],并希望像这样打印元组: [(1,2)、(1,3)、(1,4)、(2,3)、(2,4)、(3,4)] 所以通过使用 combinaList :: String -> String combinaList x = [(x,y) | x <- x, y <- drop 1 x ] combinaList::String->String 组合列表x=[(x,y)| x使用fromDa

我已经搜索并找到了一些解决方案,但没有一个像我所想的那么简单,因此您有一个数字列表
[1,2,3,4]
,并希望像这样打印元组:
[(1,2)、(1,3)、(1,4)、(2,3)、(2,4)、(3,4)]

所以通过使用

combinaList :: String -> String
combinaList x = [(x,y) | x <- x, y <- drop 1 x ]
combinaList::String->String
组合列表x=[(x,y)| x使用from
Data.List

combinaList xs = [(x, y) | (x:ys) <- tails xs, y <- ys]
combinaList xs=[(x,y)|(x:ys)使用from
Data.List

combinaList xs = [(x, y) | (x:ys) <- tails xs, y <- ys]

combinaList xs=[(x,y)|(x:ys)尝试省略类型声明。如果您不确定类型,请在
ghci
中说
:t combinaList
(在您设法编译它之后)。我是从“脚本”运行的而且不是ghci本身,当我运行此程序时它不会编译。如果某个程序不编译,请尝试其他程序。这就是
ghci
的目的。尝试忽略类型声明。如果愿意,您可以随时稍后添加一个。如果不确定类型,请在
ghci
中说
:t combinaList
(在您设法编译它之后)。我是从“脚本”运行的,而不是ghci本身,当我运行此脚本时它不会编译。如果某些内容不编译,请尝试其他内容。这就是
ghci
的目的。谢谢!这也很有意义!然而,ghci再次抱怨“不在范围内:尾部”,我不明白为什么!因为我还没有初始化字符串可能?@PabloDominguezLyons您需要导入
数据.List
:m+数据.List
导入数据.List
在ghci提示下,在源文件中导入数据.List
。您需要导入
数据.List
。在ghci中,您还可以使用完全qual未导入的已定义名称
Data.List.tails
。谢谢!这也很有意义!不过,ghci再次抱怨“不在范围内:tails”,我不明白为什么!因为我还没有初始化字符串可能?@PabloDominguezLyons您需要导入
数据.List
:m+数据.List
导入数据.List
在ghci提示下,在源文件中导入数据.List
。您需要导入
数据.List
。在ghci中,您还可以使用完全qual未导入的已定义名称
Data.List.tails