first element in list haskell
Haskell: First Element in List
To get the first element in a list in Haskell, you can use the head
function. The head
function returns the first element of a list.
Here's an example:
myList = [1, 2, 3, 4, 5]
firstElement = head myList
In this example, the variable firstElement
will be assigned the value 1
, which is the first element of the list myList
.
Please note that the head
function will throw an error if the list is empty. So, make sure to handle empty lists appropriately in your code.
[[SOURCE 1]]