Guest User

Untitled

a guest
Apr 26th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. {-
  2. - 1.
  3. - Using a library function define halve :: [a] -> ([a], [a])
  4. -}
  5. halve :: [a] -> ([a], [a])
  6. halve xs = (take h xs, drop h xs)
  7. where
  8. n = length xs
  9. h = n `div` 2
  10.  
  11. {-
  12. - 2.
  13. - Define safetail with
  14. - * conditional expression
  15. - * guarded equation
  16. - * pattern matching
  17. -}
  18.  
  19. -- safetail with conditional
  20. safetail :: [a] -> [a]
  21. safetail xs = if null xs then xs else tail xs
  22.  
  23. -- safetail with guarded equation
  24. safetail' :: [a] -> [a]
  25. safetail' xs | null xs = xs
  26. | otherwise = tail xs
  27.  
  28. -- safetail with pattern matching
  29. safetail_ :: [a] -> [a]
  30. safetail_ [] = []
  31. safetail_ xs = tail xs
Add Comment
Please, Sign In to add comment