Advertisement
flyingfisch

Untitled

Sep 23rd, 2014
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- this works
  2. elementAt :: [a] -> Int -> a
  3. elementAt [] i = error "Empty list."
  4. elementAt l i
  5.     | i < 1 = head l
  6.     | i > (length l) = last l
  7.     | otherwise = l !! (i - 1)
  8.  
  9. -- but this throws an error. why?
  10. elementAt :: (Integral b) => [a] -> b -> a
  11. elementAt [] i = error "Empty list."
  12. elementAt l i
  13.     | i < 1 = head l
  14.     | i > (length l) = last l
  15.     | otherwise = l !! (i - 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement