小编ruu*_*bel的帖子

Haskell如果否则列出理解

我正试图以正确的方式打印出一块电路板,如下所示:

  1   2   3   4   5   6   7   8   9   10  11  12  13  14  15  16  17  18  
 1.   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .         
 2.   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .         
 3.   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .         
 4.   .   .   .   .   .   . …
Run Code Online (Sandbox Code Playgroud)

haskell list-comprehension

5
推荐指数
1
解决办法
1135
查看次数

字符串的 int 元组的 Haskell 列表

我正在尝试从以下位置写出我的元组列表:

[(8,7),(5,6),(3,3),(9,4),(5,4)]
Run Code Online (Sandbox Code Playgroud)

到:

8 7 5 6 3 3 9 4 5 4
Run Code Online (Sandbox Code Playgroud)

这是我走了多远:(更新)

showTuples :: Board -> String
showTuples = unwords . fmap show . concatMap (\(x,y) -> [x,y])
Run Code Online (Sandbox Code Playgroud)

我知道我想把这个函数映射到我列表的所有元素,但我似乎做对了。

(更新)它有效,但仍然有引号问题

董事会的类型也是:

type Board = [(Int,Int)]
Run Code Online (Sandbox Code Playgroud)

string haskell tuples

2
推荐指数
1
解决办法
848
查看次数

在Lambda函数中没有show的实例?

这在ghci中运行良好:

printRobot (fight killerRobot gentleGiant)
Run Code Online (Sandbox Code Playgroud)

但这会让我看到"没有显示实例"错误,我似乎无法理解为什么.

threeRoundFight a b = 
(\a b -> printRobot (fight a b))
Run Code Online (Sandbox Code Playgroud)

这是错误:

• No instance for (Show
                     ((((t40, t50, t50) -> t50) -> t60)
                      -> (((t20, t10, t60) -> ((t20, t10, t60) -> t0) -> t0)
                          -> (([Char], a10, a0) -> [Char]) -> t30)
                      -> t30))
    arising from a use of ‘print’
    (maybe you haven't applied a function to enough arguments?)
• In the first argument of ‘print’, namely ‘it’
  In a stmt of …
Run Code Online (Sandbox Code Playgroud)

lambda haskell

-1
推荐指数
1
解决办法
103
查看次数

如何只从元组列表中获取我想要的元组?[哈斯克尔]

我试图以这种形式从整数列表中设置一个元组列表:(a,b)a < - [1..4]和b < - xs.但我不断得到声明的所有不同组合.

okTup :: [Int] -> [(Int,Int)]
okTup xs = [(i,j) | i <- [1..4], j <- xs]
Run Code Online (Sandbox Code Playgroud)

输入:okTup [3,1,4,2]

我得到的是:[(1,3),(1,1),(1,4),(1,2),(2,3),(2,1),(2,4),( 2,2),(3,3),(3,1),(3,4),(3,2),(4,3),(4,1),(4,4),(4, 2)]

但我只想这样:[(1,3),(2,1),(3,4),(4,2)]

haskell tuples list-comprehension

-2
推荐指数
1
解决办法
68
查看次数

标签 统计

haskell ×4

list-comprehension ×2

tuples ×2

lambda ×1

string ×1