程序是假設在大學哈斯克爾無法比擬型
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