模式匹配失败

时间:2012-12-03 15:12:59

标签: haskell hugs

还是我只是瞎了?

非常简单的功能,抛出“模式匹配失败:get_rtg db”

type Movie       = (Title,Regisseur,MainActors,ReleaseDate,Genre,SalesPrice)
type Title       = String
type Regisseur   = String
type Actor       = String
type MainActors  = [Actor]
type ReleaseDate = Int
data Genre       = Thriller | Fantasy | ScienceFiction | Comedy deriving (Eq,Ord,Show)
type SalesPrice  = Int
type Database    = [Movie]


-- gets all entrys which have a Regisseur, who is in MainActors at the same time
get_rtg :: Database -> [(Regisseur,Title,Genre)]
get_rtg []                             = []
ger_rtg ((ti,reg,acts,rel,gen,sal):xs) = if (isInfixOf [reg] acts) then ([(reg,ti,gen)] ++ (get_rtg xs)) else (get_rtg xs)

1 个答案:

答案 0 :(得分:5)

我想这只是一个错字:ger_rtg在最后一行声明了一个新函数,所以get_rtg现在在非[]情况下不能进行模式匹配。

另外,我会使用filter来执行此操作:

get_rtg = filter (\(_,reg,acts,_,_,_) -> reg `elem` acts)