Je construis un type de jeu dans haskell et je travaille sur la fonction de suppression et je ne peux pas faire les choses, voici mon code:liste Concaténation d'un type de données personnalisé
data Set a = Set [a] deriving (Eq,Ord,Show)
remove :: Integer -> Set Integer -> Set Integer
remove _ (Set []) = (Set [])
remove numberToRemove (Set (x:xs))
|x == numberToRemove = Set(xs)
|otherwise = Set(x:remove numberToRemove (Set xs))
Je veux pour ajouter x à l'ensemble, remove va revenir mais je ne sais pas comment l'utiliser avec mon type de données personnalisé.
Voici mon erreur:
test.hs:13:28:
Couldn't match expected type `[Integer]'
with actual type `Set Integer
In the return type of a call of `remove'
In the second argument of `(:)', namely
`remove numberToRemove (Set xs)'
In the first argument of `Set', namely
`(x : remove numberToRemove (Set xs))'
Failed, modules loaded: none.
Merci
Si vous construisez ce type de données pour le plaisir, bon pour vous! Si vous avez juste besoin d'un type de données Set pour un code que vous écrivez, il y a déjà ['Data.Set'] (http://hackage.haskell.org/packages/archive/containers/latest/doc/html/Data-Set .html) – rampion