程序是假设在大学哈斯克尔无法比拟型
data Etudiant = Etudiant CodePermanent Nom Prenom CodeProgramme deriving Show
data Inscription = Inscription CodePermanent Sigle NoGroupe CodeSession Date Date Note deriving (Show, Eq)
getCodePermanent :: Etudiant -> CodePermanent
getCodePermanent (Etudiant codePermanent _ _ _) = codePermanent
listeInscription :: Inscription -> Bool
listeInscription (Inscription _ _ _ codeSession _ _ _) = codeSession == 32003
filtreInscription1 :: [Inscription] -> [Inscription]
filtreInscription1 linscription = filter listeInscription linscription
getNoGroupe2 :: Inscription -> NoGroupe
getNoGroupe2 (Inscription _ _ noGroupe _ _ _ _) = noGroupe
numGroupesCoursEtu :: [Inscription] -> Etudiant -> [NoGroupe]
numGroupesCoursEtu listeInscr etu = map getNoGroupe2(filter (\x -> getCodePermanent(x) == getCodePermanent(etu)) listeInscr)
这里fonctions的目标是从列表[题记]匹配的会话列表[NoGroupe]解压处理学生代码32003和学生的ID:CodePermanent
我的最后一行代码给出了类型的错误...你们可以看到这个问题吗?
错误:
TP1.hs:115:54: error:
• Couldn't match type ‘Etudiant’ with ‘Inscription’
Expected type: [Inscription]
Actual type: [Etudiant]
• In the second argument of ‘map’, namely
‘(filter
(\ x -> getCodePermanent (x) == getCodePermanent (etu))
listeInscr)’
In the expression:
map
getNoGroupe2
(filter
(\ x -> getCodePermanent (x) == getCodePermanent (etu)) listeInscr)
In an equation for ‘numGroupesCoursEtu’:
numGroupesCoursEtu listeInscr etu
= map
getNoGroupe2
(filter
(\ x -> getCodePermanent (x) == getCodePermanent (etu)) listeInscr)
TP1.hs:115:114: error:
• Couldn't match type ‘Inscription’ with ‘Etudiant’
Expected type: [Etudiant]
Actual type: [Inscription]
• In the second argument of ‘filter’, namely ‘listeInscr’
In the second argument of ‘map’, namely
‘(filter
(\ x -> getCodePermanent (x) == getCodePermanent (etu))
listeInscr)’
In the expression:
map
getNoGroupe2
(filter
(\ x -> getCodePermanent (x) == getCodePermanent (etu)) listeInscr)
线115码numGroupesCoursEtu的最后一行.....
您是否尝试仔细阅读错误消息?如果是这样,你有什么困惑吗? – jberryman
我不明白如何让它们匹配... –
传递'铭文'时应该怎样做'getCodePermanent'?你的代码说什么?当你调用'getCodePermanent(etu)'时,你将'getCodePermanent'传递给'Inscription'的__list__,但它期望一个'Etudiant'。 – crockeea