99-haskell-problems/Problems 1-10/problem_3.hs

5 lines
153 B
Haskell
Raw Normal View History

2024-05-24 17:06:42 -05:00
elementAt :: (Num n, Eq n) => [a] -> n -> a
elementAt [] _ = error "Invalid index"
elementAt (hd : _) 1 = hd
elementAt (_ : tl) k = elementAt tl (k - 1)