Quick response:
One easy way is to use the sum function from Data.List .
Then you could just say:
summation xy = sum [x .. y]
This solution assumes x less than y , and you can fix it by saying:
summation xy = sum [min xy .. max xy]
Definition of sum :
As you study Haskell, it may be important to know how sum works and not just to know that it exists. For me, the biggest hurdle to get started was to write too many functions that already existed; especially since I did not know how to write them effectively.
Hoogle is a big help in this regard: it is a search engine that allows you to browse Haskell features. This is great for performance, because you can spend time working on your problem, instead of creating bad rewrites of half the foreplay. This is also great for learning, because there are links to the source code of most functions on Hackage . The source code for Prelude and other "fundamental" libraries, such as Data.List , is surprisingly accessible to beginners and will give a lot of information about how "smart children" do something.
The :browse command in GHCI is something that I recently learned about, which, as I would like, I discovered earlier.
In any case, one way to determine sum is to use a fold:
sum xs y = foldl (+) 0 xs
Or the equivalent in a "meaningless" style :
sum = foldl (+) 0
I usually prefer the first wording, but knowing how and why the second works will help you on your journey.
Further reading:
You will notice that I used the foldl function. This function collapses the input list. To βmasterβ functional programming, knowing how to fold is one of the most basic and important concepts. A good resource for advice is the fold page from the Haskell Wiki .