integerList = [1] ++ integerList
(head (tail integerList))
I have run this code and the result is 1 and that it is an endless recursion.
I am trying to figure out how haskell calculates these functions. Can someone write down the process. I would like to visualize it. Thanks!
head returns the first element of a list. In this case it returns the first element of the list tail integerList. tail returns the original list without the first element. The original list is integerList which is bound to [1] ++ integerList. The ++ operator concatenates two lists, so the resulting list is 1 : integerList. Applying tail to this list gives integerList, so tail integerList simply yields integerList.
Back to the beginning: substitute tail integerList with integerList (since that's what it evaluates to) to get head integerList. Reminder: integerList evaluates to 1 : integerList. Applying head to that we get 1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With