Introduction To Haskell
Ranges

Introduction

Ranges are a useful way to specify the contents of a list you want to define. You can do this with numeric or character data as long as you stick to only one type.

WinGHCI

To make your list count backwards, you have to show the decrement by including 2 terms at the start.

WinGHCI

Alternatively, you can just reverse the list.

WinGHCI

If you don't specify the end of the list, it will be of infinite length.

WinGHCI

WinGHCi will output an infinite list but it's not worth doing more than once just to see. You would normally make an infinite list knowing that you are going to take a number of elements from the list to form a result to be used elsewhere.

Haskell does not evaluate an infinite list until you take elements from it.

Cycling, Repeating & Replicating

These 3 functions are quite useful when creating lists. You can see the format of these functions in the following examples.

WinGHCI