Jump to content

Recommended Posts

Posted (edited)

eu tenho o seguinte codigo:

--turma: [(1,"Passos Coelho",4.0,3.0),(2,"Miguel Caraças",10.0,6.0),(3,"Fernando Pessoa",8.0,3.0),(4,"Zé do Pipo",4.0,2.0)]
type Aluno = (Numero,Nome,ParteI,ParteII)
type Nome = String
type Numero = Int
type ParteI = Float
type ParteII = Float
type Turma = [Aluno]
--b) testar alunos que passaram
alunosPositiva:: Turma -> Turma
alunosPositiva (x:xs) = if alunoPassou x then x:alunosPositiva xs
 else alunosPositiva xs
alunosPositiva [] = []
alunoPassou:: Aluno -> Bool
alunoPassou (_,_,a,b) = (a>=8) && (a+b >= 9.5)
--c)
type NotaFinal = (Numero,String,Float)
notafinal:: Turma -> [NotaFinal]
notafinal t = notafinalAux $ alunosPositiva t
notafinalAux:: Turma -> [NotaFinal]
notafinalAux ((c,n,a,b):xs) = (c,n,a+b):notafinalAux xs
notafinalAux [] = []

o problema está aqui:

--d) media dos alunos que passaram
mediaFinal:: Turma -> Float
mediaFinal t = (sum (map getnota (notafinal t))) / (length (notafinal t))

getnota:: NotaFinal -> Float
getnota (_,_,n) = n

quando fasso o load para o ghci dá-me

Couldn't match expected type `Float' with actual type `Int'
In the return type of a call of `length'
In the second argument of `(/)', namely `(length (notafinal t))'
In the expression:
 (sum (map getnota (notafinal t))) / (length (notafinal t))

Se fizer separadamente o "length (notafinal t)" da-me 2 tudo ok - não percebo porque não consegue dividir por 2 -.-

Cumprimentos 😉

Edited by Baderous
geshi

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.