[Haskell-beginners] Re: folds again -- myCycle
will_n48 at yahoo.com
Wed Mar 18 07:19:29 EDT 2009
Bas van Dijk <v.dijk.bas <at> gmail.com> writes:
> On Sun, Mar 15, 2009 at 7:35 PM, Will Ness <will_n48 <at> yahoo.com> wrote:
> > which is then just rewritable as:
> > myCycle xs = ys where ys = foldr (:) ys xs
> > or (arriving at the same result)
> > myCycle xs = foldr (:) (myCycle xs) xs
> Note that, because 'ys' only has to be calculated once, GHC makes the
> most efficient code for the former one. In the latter 'myCycle xs' has
> to be calculated each time 'xs' runs empty.
Actually my point was, that
" I find that "where" rewrites are easier to comprehend for me,
more often than not. :) "
" myCycle xs = ys where ys = foldr (:) ys xs "
which should be exactly as the one with the let.
More information about the Beginners