How does variable binding work with recursion in Haskell?

Viewed 1394

I was reading about Haskell and it stated that once a variable is bound to an expression it cannot be rebound for example

x = 10
x = 11

Assign.hs:2:1: error:
    Multiple declarations of ‘x’
    Declared at: Assign.hs:1:1
                 Assign.hs:2:1

So if this is the case... how is recursion working where the same variable keeps getting bound to other things? For example

drop n xs = if n <= 0 || null xs
              then xs
              else drop (n-1) (tail xs)

the variable n... is being bound again and again every time the function recurses. Why is this allowed?

Also if you guys could tell me some key words to search for so I can learn more about this myself I'd highly appreciate it.

3 Answers
Related