Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It looks like he is trying to keep track of players (NombreJug = player name), PuntosLogrados (points gained) and playing times (MinutosJugados) and then find the best player by some criteria. </p> <p>armarListaDeTuplasPuntosFecha throws away the playing times to return a tuple of player name and points.</p> <p>mejorJugadorPor ("Best player by") is trying to ask the user for a list of inputs and then select the player with the highest score. I think you are right that he needs a Read instance for his type, or a function to parse the input and turn it into type Fecha defined at the top. It also depends on how NombreJug,PuntosLogrados,MinutosJugados are defined. Are they type synonyms?</p> <p>mejorJugadorPor also looks like it should be of type String-> IO NombreJug, since it performs IO actions. </p> <hr> <p>This is my attempt to do what you want:</p> <pre><code>import Data.List type NombreJug = String type PuntosLogrados = Int type MinutosJugados = Int type Fecha = [(NombreJug,PuntosLogrados,MinutosJugados)] armarListaDeTuplasPuntosFecha::Fecha-&gt;[(NombreJug,PuntosLogrados)] armarListaDeTuplasPuntosFecha = map desechar where desechar (x,y,_) = (x,y) jugadorConMayorCantidadDePuntoEnFecha unaFecha = fst (maximumBy mayorTupla (armarListaDeTuplasPuntosFecha unaFecha)) mayorTupla = undefined mejorJugadorPor:: String -&gt; IO NombreJug mejorJugadorPor criterio | criterio == "Mayor Cantidad de puntos en fecha" = do fecha &lt;- readLn return $ jugadorConMayorCantidadDePuntoEnFecha fecha | otherwise = return "No es un criterio valido, reintente una proxima vez" </code></pre> <p>I added "mayorTupla = undefined" to get it to compile, because that function isn't defined in the code you posted.</p> <p>Changes I made:</p> <ol> <li><p>your function armarListaDeTuplasPuntosFecha is better expressed with map. Map applies a function to every element of a list, which is what you are doing manually.</p></li> <li><p>jugadorConMayorCantidadDePuntoEnFecha can be expressed with fst, which returns the first element of a tuple of two values</p></li> <li><p>mejorJugadorPor needs to be in the IO monad because it performs input/output actions (reading something in that the user types). You do this by change the return type from String to IO String, to say that the return value depends on IO (ie the function isn't pure).</p></li> <li><p>The function readLn does what you want, because it converts the input string to the correct type as long as the type has an instance of Read. The Read type class basically means that you can convert a string into a value of the type somehow.</p></li> <li><p>Because mejorJugadorPor is monadic, you need to make sure that the value it returns is contained in the IO monad. This is what the function return does: it takes a value of type "a" and turns it into a value of type "m a", where m is any monad.</p></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload