Jack Henahan jhenahan at uvm.edu
Tue Apr 17 05:18:43 CEST 2012

```sumOfSquares, sumOfSquares', sumOfSquares''  :: Int -> Int
sumOfSquares n = sum [x^2 | x <- [1..n]] -- list comprehensions
sumOfSquares' n = sum \$ map (^2) [1..n] -- (\$) for function application and explicit use of map
sumOfSquares'' = sum . map (^2) . enumFromTo 1 -- pointfree style

sumOfSquares''' :: Int -> (Int -> r) -> r
sumOfSquares''' n k = k . sum \$ map (^2) [1..n] -- A very contrived bit of continuation passing style (k is the continuation)

I'll try to come up with more. I'm sure others on the list can come up with more varied stuff.

Jack Henahan
jhenahan at uvm.edu
==
Computer science is no more about computers than astronomy is about telescopes.
-- Michael R. Fellows
==
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PublicKey.asc
Type: application/x-apple-msg-attachment
Size: 24255 bytes
Desc: not available
-------------- next part --------------

On Apr 16, 2012, at 12:46 PM, Nikita Beloglazov <nikita at taste-o-code.com> wrote:

> Hi.
> I'm building website where people can try and "taste" new languages by solving small or mediums size tasks. Tasks are language specific and should show best features of the language. Website is not meant to teach new language but to give idea what is this language good for.
> Now I want to add Haskell. I need about 7-10 tasks for now. First three of four tasks are introductory, they should show/check basics of haskell. E.g. given n, return sum of squares of first n even numbers. Other tasks are more complicated and show advantages of functional programming in general or some specific haskell features.
> I don't have any experience with haskell and I need you help. Could you help me with ideas for tasks?
>
> Thank you,
> Nikita Beloglazov
> _______________________________________________
> Beginners mailing list