Introduction to Haskell Ranges

This article is the second installation on my Introduction to Haskell series. After the first article did well I was very pumped up to write another Haskell article.

We will be discussing about Haskell ranges.

Haskell Ranges

Haskell is cool. Ranges are cool too. Imagine you need a list which contains numbers between 1 to 20. You can just type the list out but you can also use ranges. Let’s have a look.

That’s it.
I know its magic.
Ranges allow you to define a lower limit and an upper limit and it will take care of the rest.

Addition to these you can also specify a step. Imagine you need a list of every even number between 1 to 20.

Whenever you need to specify a step just separate the first 2 elements with a comma and then specify your upper limit. For e.g, if you need a list with every third number between 1 to 30 just type

But remember you cannot provide more than one step to ranges.
Another cool thing about ranges is that also works with alphabets. Yes they do. Let’s have a look

You can also provide a step

You need a infinte list? Ranges to the rescue

You can also create a reversed number list with ranges

That’s it for this article. You can browse the first article here Introduction to Haskell ( Why you should learn it if you are a Javascript developer )

If you have any questions and suggestions feel free to comment.

Really loved this article?

Then subscribe to my blog. You will receive articles like this one directly in your Inbox frequently.

Here are more articles for you.

1 thought on “Introduction to Haskell Ranges”

  1. I precisely desired to say thanks again. I am not sure the things that I could possibly have achieved in the absence of the creative ideas provided by you relating to this subject matter. It absolutely was a frightening concern in my circumstances, however , taking note of a skilled fashion you resolved that took me to leap for delight. I will be grateful for your service and as well , expect you are aware of a great job that you’re putting in training people via your websites. Most likely you have never got to know any of us.

Leave a Reply

Your email address will not be published. Required fields are marked *