Je commence à programmer avec haskell. Le programme que je développe résume simplement le total d'une liste avec deux elementes, par exemple:Impossible de trouver le type attendu `[([Char], a0)] 'avec le type actuel` ([Char], t0)' Haskell
[("book",10),("cookies",2),("icecream",5)]
Cela devrait retourner « 17 ». Ici, je mon code:
total [] = []
total ([("c",e)]:y) = total y ++ [e]
Mais en cours d'exécution en GHCi il me donne cette erreur:
<interactive>:80:8:
Couldn't match expected type `[([Char], a0)]'
with actual type `([Char], t0)'
In the expression: ("livro", 10)
In the first argument of `total', namely
`[("livro", 10), ("bolachas", 2), ("gelado", 5)]'
In the expression:
total [("livro", 10), ("bolachas", 2), ("gelado", 5)]
<interactive>:80:21:
Couldn't match expected type `[([Char], a0)]'
with actual type `([Char], t1)'
In the expression: ("bolachas", 2)
In the first argument of `total', namely
`[("livro", 10), ("bolachas", 2), ("gelado", 5)]'
In the expression:
total [("livro", 10), ("bolachas", 2), ("gelado", 5)]
<interactive>:80:36:
Couldn't match expected type `[([Char], a0)]'
with actual type `([Char], t2)'
In the expression: ("gelado", 5)
In the first argument of `total', namely
`[("livro", 10), ("bolachas", 2), ("gelado", 5)]'
In the expression:
total [("livro", 10), ("bolachas", 2), ("gelado", 5)]
Ceci est probablement très simple, mais en tant que débutant, je n'a pas été en mesure de résoudre ce problème.
Merci, ça marche maintenant (: – magamig