nombresDeUsuarios :: RedSocial -> [String] nombresDeUsuarios ([], , ) = []…
- User
nombresDeUsuarios :: RedSocial -> [String] nombresDeUsuarios ([], _, _) = [] nombresDeUsuarios (u:us, _, _) = (show (snd u)):(nombresDeUsuarios (us, _, _) ) Whats wrong with this code? iap1-tp.hs:41:76: error: [GHC-88464] * Found hole: _ :: [Publicacion] * In the first argument of
nombresDeUsuarios', namely(us, _, _)' In the second argument of(:)', namely(nombresDeUsuarios (us, _, _))' In the expression: (show (snd u)) : (nombresDeUsuarios (us, _, _)) * Relevant bindings include us :: [Usuario] (bound at iap1-tp.hs:41:22) u :: Usuario (bound at iap1-tp.hs:41:20) nombresDeUsuarios :: RedSocial -> [String] (bound at iap1-tp.hs:40:1) Valid hole fits include [] :: forall a. [a] with [] @Publicacion (bound at ) mempty :: forall a. Monoid a => a with mempty @[Publicacion] (imported fromPrelude' at iap1-tp.hs:1:1 (and originally defined inGHC.Base')) | - Assistant
The issue with this code is that the hole "_" is being used as a pattern match, which is causing an error. Instead, you should use a variable in the pattern, and then ignore it.
Here's a corrected version of the function:
hsnombresDeUsuarios :: RedSocial -> [String] nombresDeUsuarios ([], _, _) = [] nombresDeUsuarios (u:us, pubs, r) = (show (snd u)):(nombresDeUsuarios (us, pubs, r))In this version, I replaced the holes "_" with variables
pubsandr. This way, the pattern matching can still work correctly, and the unused variables won't cause any issues. - User
Como ponerle nombre al modulo?
- Assistant
Para ponerle nombre a un módulo en Haskell, simplemente usa la palabra clave
moduleseguida del nombre del módulo que deseas, en la primera línea del archivo. Por ejemplo, si quieres llamar al módulo "MiModulo", entonces la primera línea de tu archivo de código fuente sería:haskellmodule MiModulo whereDespués de esto, puedes especificar las funciones, tipos de datos y demás elementos que forman parte de tu módulo. Asegúrate de guardar el archivo con el nombre del módulo, en este caso "MiModulo.hs". Así, otros archivos de Haskell pueden importar y utilizar este módulo con la instrucción:
haskellimport MiModuloAquí hay un ejemplo completo de cómo se vería un módulo simple llamado "MiModulo":
haskell-- MiModulo.hs module MiModulo where saludar :: String -> String saludar nombre = "Hola " ++ nombre ++ "!"