[Haskell-beginners] Re: folds again -- myCycle
Will Ness
will_n48 at yahoo.com
Wed Mar 18 14:10:13 EDT 2009
Daniel Fischer <daniel.is.fischer <at> web.de> writes:
>
> Am Mittwoch, 18. März 2009 16:14 schrieb Will Ness:
> >
> > sum $ take m $ cycle [1..k]
> > | n > 0 = x*n+y
> > where
> > (n,r) = quotRem m k
> > x = sum [1..k]
> > y = sum [1..r]
In fact, the super brilliant deducting compiler would make it
sum $ take m $ cycle [1..k]
| n > 0 = x*n+y
where
(n,r) = quotRem m k
x = k*(k+1)/2
y = r*(r+1)/2
:) :)
More information about the Beginners
mailing list