Are functions with a recursive tail

I was wondering if funtions with guards can be tail recursively. Given this implementation elemfor example

elem' :: (Eq a) => a -> [a] -> Bool
elem' x [] = False
elem' x (y:ys)
    | x == y       = True
    | otherwise    = elem' x ys

Is this tail recursive? I would say yes, but somehow I’m not convinced.

+4
source share
1 answer

Yes, this tail is recursive.

One possible definition of what “Recursive Tail” means in the Haskell context is that calls to junction points are valid because they can only appear in tail recursive positions. On page 3 of Compiling without Continuations, we find the following figure:

Tail contexts

, case . , GHC.

Haskell, , case -, .

( , "elem' - " - .)

+9

Source: https://habr.com/ru/post/1696066/


All Articles