summaryrefslogtreecommitdiff
path: root/1-10/3.hs
diff options
context:
space:
mode:
Diffstat (limited to '1-10/3.hs')
-rw-r--r--1-10/3.hs5
1 files changed, 5 insertions, 0 deletions
diff --git a/1-10/3.hs b/1-10/3.hs
new file mode 100644
index 0000000..660ae64
--- /dev/null
+++ b/1-10/3.hs
@@ -0,0 +1,5 @@
+elementAt [] _ = error "out of range"
+elementAt (x:_) 1 = x
+elementAt (_:xs) k
+ | k < 1 = error "out of range" -- deal with the infinite list
+ | otherwise = elementAt xs (k - 1)