Haskell 哈斯克尔不能';t匹配类型

Haskell 哈斯克尔不能';t匹配类型,haskell,Haskell,这个项目应该是针对大学里的学生的 data Etudiant = Etudiant CodePermanent Nom Prenom CodeProgramme deriving Show data Inscription = Inscription CodePermanent Sigle NoGroupe CodeSession Date Date Note deriving (Show, Eq) getCodePermanent :: Etudiant -> CodePermanen

这个项目应该是针对大学里的学生的

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)
这里的功能的目标是从列表[题词]中提取一个与会话代码32003和学生id:CodePermanent匹配的列表[NoGroup]

我的最后一行代码返回了一个类型错误。。。你们能看到问题吗

错误:

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…的最后一行。

getCodePermanent::Etudiant->CodePermanent

请注意,
getCodePermanent
Etudiant
作为参数

(\x -> getCodePermanent(x) == getCodePermanent(etu))

假设您正在尝试检查
铭文
是否与给定的
Etudiant
具有相同的
code永久性
。但正如我前面所说,
getCodePermanent
Etudiant
作为参数。您需要编写另一个函数以从
铭文中获取
code永久性

您是否仔细阅读了错误消息?如果是这样的话,是什么让你感到困惑呢?我不知道如何让它们匹配……当传递一个
铭文时,
getCodePermanent
应该怎么做?你的代码怎么说?当你调用
getCodePermanent(etu)
时,你正在传递
getCodePermanent
一个
铭文列表
s,但它需要一个
Etudiant
。好的,我的目标是获得学生x(传入参数:Etudiant)在学期代码32003(codeSession=32003)的组课程号(noGroup)。因此,首先我必须得到课程列表,课程代码为:32003,然后在该列表中,我必须找到与传入numGroupeCoursEtu参数的Etudiant匹配的codePermanent,以最终得到学生在一行中遵循的课程编号列表(NoCours)。将其分解,并将之前注释中的每一步都作为顶级函数实现。当它工作时,您可以将这些函数放入where子句中。谢谢!我添加了这两行代码:getCodePermanent2::铭文->CodePermanentGetCodePermanent2(铭文CodePermanent2)=CodePermanent2,现在它工作了@这就是嘉明旺的想法。尽管如此,我还是建议你找一个更好的名字。@JiaMingWang请记住在你有能力的时候接受我的回答