Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: Are these soloutions all valid and a good use of Haskell
(Chris Linton-Ford)
2. Re: Are these soloutions all valid and a good use of Haskell
(Frerich Raabe)
----------------------------------------------------------------------
Message: 1
Date: Mon, 10 Nov 2014 10:29:29 +0000
From: Chris Linton-Ford <[email protected]>
To: "The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell" <[email protected]>
Subject: Re: [Haskell-beginners] Are these soloutions all valid and a
good use of Haskell
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
Never mind - I should have Googled this:
https://www.haskell.org/haskellwiki/Haskell_programming_tips#Avoid_explicit_recursion
Chris
-----Original Message-----
From: Beginners [mailto:[email protected]] On Behalf Of Chris
Linton-Ford
Sent: Monday, November 10, 2014 10:25 AM
To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level
topics related to Haskell
Subject: Re: [Haskell-beginners] Are these soloutions all valid and a good use
of Haskell
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:[email protected]] On Behalf Of Karl Voelker
Sent: Monday, November 10, 2014 10:17 AM
To: [email protected]
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
[email protected]
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
_______________________________________________
Beginners mailing list
[email protected]
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
------------------------------
Message: 2
Date: Mon, 10 Nov 2014 11:43:56 +0100
From: Frerich Raabe <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Are these soloutions all valid and a
good use of Haskell
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII; format=flowed
On 2014-11-10 11:16, Karl Voelker wrote:
> 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.
In addition to what Karl wrote, I'd like to suggest not using the semicolon
all the time -- it's not needed and just adds noise.
> 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.
Right - I suggest trying to express the problem with the most abstract
function first, then consider using a fold, then use manual recursion. in
your particular case you could exploit that for non-empty lists, getting
the last element of a list is the same as getting the first element of
a reversed list (and there are ready-made functions for reversing a list
and getting the first element of a list).
--
Frerich Raabe - [email protected]
www.froglogic.com - Multi-Platform GUI Testing
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 77, Issue 5
****************************************