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 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.
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
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.