<div dir="ltr"><div dir="ltr"><div dir="ltr">Hi,<div>if it is ok for you to work only with lists (not generic foldables), you could write it this way:</div><div><br></div><div><font face="monospace">maximumBy cmp [x] = x<br>maximumBy cmp (x:y:xs) = if (cmp x y)==GT then maximumBy cmp (x:xs) else maximumBy cmp (y:xs)</font><br></div><div><br></div><div>the signature is </div><div><font face="monospace">maximumBy :: (a -> a -> Ordering) -> [a] -> a</font></div><div><br></div><div>Ut</div><div><br></div><div><br></div></div></div><div id="m_-9203042563784922724DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2"><br> <table style="border-top:1px solid #d3d4de">
        <tbody><tr>
      <td style="width:55px;padding-top:18px"><a href="http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail" target="_blank"><img src="https://ipmcdn.avast.com/images/icons/icon-envelope-tick-green-avg-v1.png" alt="" width="46" height="29" style="width:46px;height:29px"></a></td>
                <td style="width:470px;padding-top:17px;color:#41424e;font-size:13px;font-family:Arial,Helvetica,sans-serif;line-height:18px">Mail priva di virus. <a href="http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail" style="color:#4453ea" target="_blank">www.avg.com</a>                 </td>
        </tr>
</tbody></table>
<a href="#m_-9203042563784922724_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2" width="1" height="1"></a></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Il giorno ven 22 mag 2020 alle ore 20:53 Alexander Chen <<a href="mailto:alexander@chenjia.nl" target="_blank">alexander@chenjia.nl</a>> ha scritto:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="font-family:Arial;font-size:13px">Hi,<div><br></div><div>maximumBy :: Foldable t => (a -> a -> Ordering) -> t a -> a</div><div><br></div><div>its in the Data.List<br><br><div>May 22, 2020 8:33:33 PM CEST "Daniel van de Ghinste (Lord_Luvat)" <<a href="mailto:danielvandeghinste@gmail.com" target="_blank">danielvandeghinste@gmail.com</a>> wrote:<blockquote type="cite">Hi,<div><br></div><div>Maybe I’m on a different version, but I don’t see a function called maximumBy in my base Prelude. Can you give us a type signature for the function? If you’re not sure how to do that just type:</div><div>Prelude> :t maximumBy</div><div>In your ghci interpreter and it should return the type signature of whatever you have after ‘:t ‘ (this works for compound expressions too if you put them in brackets)</div><div><br></div><div>Perhaps maximumBy is what you’re meant to call your rewrite of the existing function I see called ‘maximum’ (seems to do the same thing). Let me know if thats the case and I can explain how it works.</div><div><br></div><div><br><div>
<div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">Best regards,</div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">Daniel van de Ghinste</div><div style="color:rgb(0,0,0);font-family:Helvetica;font-size:12px;font-style:normal;font-variant-caps:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div></div></div><div><blockquote type="cite"><div>On 22 May 2020, at 20:20, Alexander Chen <<a href="mailto:alexander@chenjia.nl" target="_blank">alexander@chenjia.nl</a>> wrote:</div><br><div><div style="font-family:Arial;font-size:13px">Hi,<div><br></div><div>I want to re-write a function maximumBy (its an assignment).</div><div><br></div><div>However, I don't get how it works.</div><div><br></div><div>>maximumBy compare [1,53,9001, 10]</div><div>9001</div><div><br></div><div>but what does it actually do to get there? </div><div><br></div><div>thanks in advance.</div><div><br></div><div>best,<br><br><div><div style="font-family:Arial;font-size:13px"><br></div></div></div></div>_______________________________________________<br>Beginners mailing list<br><a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br><a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br></div></blockquote></div><br></div></blockquote></div><br><br><div><div style="font-family:Arial;font-size:13px"><br></div></div></div></div>_______________________________________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org" target="_blank">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br>
</blockquote></div>
<div id="DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2"><br> <table style="border-top:1px solid #d3d4de">
        <tr>
      <td style="width:55px;padding-top:18px"><a href="http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail" target="_blank"><img src="https://ipmcdn.avast.com/images/icons/icon-envelope-tick-green-avg-v1.png" alt="" width="46" height="29" style="width: 46px; height: 29px;"></a></td>
                <td style="width:470px;padding-top:17px;color:#41424e;font-size:13px;font-family:Arial,Helvetica,sans-serif;line-height:18px">Mail priva di virus. <a href="http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail" target="_blank" style="color:#4453ea">www.avg.com</a>                 </td>
        </tr>
</table>
<a href="#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2" width="1" height="1"></a></div>