[Haskell-beginners] Are these soloutions all valid and a good use of Haskell

Chris Linton-Ford clintonf at kcg.com
Mon Nov 10 10:24:57 UTC 2014


I've seen this mentioned a couple of times - that you should avoid explicit recursion where possible in Haskell (although I can't find the references now).

Is this to make programs easier to understand, or more compact, or is there a performance benefit?

Chris



-----Original Message-----
From: Beginners [mailto:beginners-bounces at haskell.org] On Behalf Of Karl Voelker
Sent: Monday, November 10, 2014 10:17 AM
To: beginners at haskell.org
Subject: Re: [Haskell-beginners] Are these soloutions all valid and a good use of Haskell

On Mon, Nov 10, 2014, at 01:50 AM, Roelof Wobben wrote:
> What do you experts think of the different ways ?

2 and 4 are quite similar, and both fine. 3 is not so good: guards provide weaker guarantees than patterns, and head and tail are partial functions.

All three implementations have in common that they do their own recursion. It would be a good exercise to try implementing last as a fold - in other words, letting the standard library do the recursion for you.

-Karl
_______________________________________________
Beginners mailing list
Beginners at haskell.org
http://www.haskell.org/mailman/listinfo/beginners
KCG Europe Limited is authorized and regulated by the Financial Conduct Authority. Registered Office 55 Basinghall Street, London, EC2V 5DU. Registered in England & Wales No. 03632121

This e-mail and its attachments are intended only for the individual or entity to whom it is addressed and may contain information that is confidential, privileged, inside information, or subject to other restrictions on use or disclosure. Any unauthorized use, dissemination or copying of this transmission or the information in it is prohibited and may be unlawful. If you have received this transmission in error, please notify the sender immediately by return e-mail, and permanently delete or destroy this e-mail, any attachments, and all copies (digital or paper). Unless expressly stated in this e-mail, nothing in this message should be construed as a digital or electronic signature. For additional important disclaimers and disclosures regarding KCG’s products and services, please click on the following link:

http://www.kcg.com/legal/global-disclosures


More information about the Beginners mailing list