sent Posted October 14, 2012 at 05:47 PM Report #479124 Posted October 14, 2012 at 05:47 PM (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 October 14, 2012 at 09:31 PM by Baderous geshi
Baderous Posted October 14, 2012 at 09:32 PM Report #479165 Posted October 14, 2012 at 09:32 PM Está aqui a explicação: https://www.portugal-a-programar.pt/topic/47657-duvida-a-calcular-media/
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now