import Data.Char
-- Sample test data
testData :: [Movies]
testData = [("Me and My Broken Heart","Rixton"),
("It’s My Birthday","will.i.am"),
("Problem","Ariana Grande")]
-- record a sale of a track
record :: [Movies] -> String -> String
record t a = []
record ((t, a): xs) a a
| t == a && a == a = [(t,a)]
| otherwise = record xs a t
Run Code Online (Sandbox Code Playgroud)
正确的输出应该是数据库的修改版本.
import Data.Char
import Data.List
import Data.Maybe
-- Sample test data
type Movies = (String, String)
sample :: [Movies]
sample = [("I am legend","Will Smith"),
("Rise of the Planet of the Apes","James Franco"),
("Godzilla","Bryan Cranston")]
sellTicket :: [Movies] -> String -> String -> [Movies]
sellTicket [] _ _ = []
sellTicket ((title, actor): xs) aTitle anActor
| title == aTitle && actor == anActor =
(title, actor):sellTicket xs aTitle anActor
| otherwise = (title,actor):sellTicket xs aTitle anActor
Run Code Online (Sandbox Code Playgroud)
谢谢大家的帮助,现在一切正常.
而詹姆斯弗兰科则崛起了猿星球.
如何根据第一个元素或第二个或第三个元素搜索元组?
我知道如何搜索两个元组,但我怎么做两个以上呢?
type Stuff = (String, String, Int)
testStuff :: [Stuff]
testStuff = [
("beans","black",5),
("cod","fish",4),
("coke","diet",3)
]
Run Code Online (Sandbox Code Playgroud)
如何编写一个搜索"Stuff"并返回"int"值的函数?
例如,searchStuff"beans"应该返回5.
haskell ×3