I was doing an assignment for my class, where I have to add up all of the items within a list. I was confused about how to do it, since I was told that you can not access individual items within a list like how you can in Python.
The way that I found how most people did it was using something like the following method
let rec list_sum lst =
match lst with
| [] -> 0
| hd :: tl -> hd + list_sum tl
My question is, where does the hd and tl come from? The people who wrote the code never predefined these variables or anything, so are you allowed to just write them like that? How do they know what list that you are talking about?