[Haskell-beginners] Better way to write this?

Tim Perry perry2of5 at yahoo.com
Tue Mar 9 18:39:51 EST 2010


Thanks Brent, Stephen, Mihai, and Rahul,

I finally understand lambda expressions :)  The combination of your comments got me there and "Learn you a haskell" solidified it. I've now written 3 working lambda expression in my life (without copying).

Thanks again,
--Tim





----- Original Message ----
From: Brent Yorgey <byorgey at seas.upenn.edu>
To: beginners at haskell.org
Sent: Tue, March 9, 2010 2:28:51 PM
Subject: Re: [Haskell-beginners] Better way to write this?

On Tue, Mar 09, 2010 at 10:35:06PM +0200, Mihai Maruseac wrote:
> 
> myLength xs = foldl addOne 0 xs
>   where addOne x n = n + 1

Almost, Tim's original addOne is actually 

  addOne x n = x + 1

The difference is that the given solution uses foldr whereas Tim was
using foldl.  Either one works in this case since + is commutative.

-Brent
_______________________________________________
Beginners mailing list
Beginners at haskell.org
http://www.haskell.org/mailman/listinfo/beginners



More information about the Beginners mailing list