
Hi, if it is ok for you to work only with lists (not generic foldables), you could write it this way: maximumBy cmp [x] = x maximumBy cmp (x:y:xs) = if (cmp x y)==GT then maximumBy cmp (x:xs) else maximumBy cmp (y:xs) the signature is maximumBy :: (a -> a -> Ordering) -> [a] -> a Ut http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail Mail priva di virus. www.avg.com http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail <#m_-9203042563784922724_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2> Il giorno ven 22 mag 2020 alle ore 20:53 Alexander Chen < alexander@chenjia.nl> ha scritto:
Hi,
maximumBy :: Foldable t => (a -> a -> Ordering) -> t a -> a
its in the Data.List
May 22, 2020 8:33:33 PM CEST "Daniel van de Ghinste (Lord_Luvat)" < danielvandeghinste@gmail.com> wrote:
Hi,
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: Prelude> :t maximumBy 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)
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.
Best regards, Daniel van de Ghinste
On 22 May 2020, at 20:20, Alexander Chen
wrote: Hi,
I want to re-write a function maximumBy (its an assignment).
However, I don't get how it works.
maximumBy compare [1,53,9001, 10] 9001
but what does it actually do to get there?
thanks in advance.
best,
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail Mail priva di virus. www.avg.com http://www.avg.com/email-signature?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>