99-haskell-problems/Problems 01-10/problem_03.hs

4 lines
153 B
Haskell

elementAt :: (Num n, Eq n) => [a] -> n -> a
elementAt [] _ = error "Invalid index"
elementAt (hd : _) 1 = hd
elementAt (_ : tl) k = elementAt tl (k - 1)