Advertisement
Guest User

Untitled

a guest
Jul 1st, 2015
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. module Q02 where
  2.  
  3. myButLastTest :: [a] -> Either a String
  4. myButLastTest (x:y:[]) = Left x
  5. myButLastTest (x:[]) = Right "Cannot obtain myButLast of a list with one element"
  6. myButLastTest [] = Right "Cannot obtain myButLast of an empty list"
  7. myButLastTest (_:t) = myButLastTest(t)
  8.  
  9. myButLast :: [a] -> a
  10. myButLast y = case myButLastTest(y) of (Left x) -> x
  11. (Right y) -> error y
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement