列出具有数组条件的理解?

时间:2017-03-29 21:53:47

标签: arrays haskell tuples conditional list-comprehension

我有一个包含如下所示元组的数组:[((Int, Int), Int)]。我正在尝试使用列表推导创建一个新数组,如果第3个Int ==某个数字,则表示只添加所有3个Ints。我把它写成

newArray = [((x,y),z) | ((x,y),z)<-oldArray, (snd oldArray) == 5]

但是,当我尝试运行包含此代码的代码时,它表示“无法匹配预期类型”并将错误指向我的条件。 "Couldn't match expected type '(a0, Int)' with actual type '[((Int, Int), Int)]'"

1 个答案:

答案 0 :(得分:3)

orientdb> connect remote:localhost root root Disconnecting from the database [null]...OK Connecting to remote Server instance [remote:localhost] with user 'root'...OK orientdb {server=remote:localhost/}> list databases Found 5 databases: * VehicleHistoryGraph (plocal) * GratefulDeadConcerts (plocal) * OpenBeer (plocal) * BetterDemo (plocal) * Tolkien-Arda (plocal) orientdb {server=remote:localhost/}> connect plocal:../databases/GratefulDeadConcerts root root Disconnecting from remote server [remote:localhost/]... OK Connecting to database [plocal:../databases/GratefulDeadConcerts] with user 'root'... Error: com.orientechnologies.orient.core.exception.OStorageException: Cannot open local storage '../databases/GratefulDeadConcerts' with mode=rw DB name="GratefulDeadConcerts" Error: com.orientechnologies.orient.core.exception.OStorageException: Cannot open the storage 'GratefulDeadConcerts' because it does not exist in path: ../databases/GratefulDeadConcerts DB name="GratefulDeadConcerts" 是一个列表,总是永远,甚至在理解范围内,因此oldArray无法应用于它。请改用snd