For Example: List is [5,6,7,78,8,7]
Element at index 3 is 78
The code will be
elemAt :: [a] -> Int -> a
elemAt (ele:list) 0 = ele
elemAt (ele:list) i = elemAt list (i-1)
This program basically decreases n on each iteration and when it reaches zero it will return the element at the head of list
The output is
Do give a thumbs up and in case there are doubts leave a comment.
Get Answers For Free
Most questions answered within 1 hours.