Guest User

Untitled

a guest
Apr 26th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. -- using conditionals
  2. safetail :: [a] -> [a]
  3. safetail a = if null a then [] else tail a
  4.  
  5. -- using guarded equations
  6. safetail' :: [a] -> [a]
  7. safetail' xs | null xs = []
  8. | otherwise = tail xs
  9.  
  10. -- using pattern matching
  11. safetail'' :: [a] -> [a]
  12. safetail'' [] = []
  13. safetail'' (_:xs) = xs
  14.  
  15. -- my or operator
  16. (||!) :: Bool -> Bool -> Bool
  17. True ||! True = True
  18. True ||! False = True
  19. False ||! True = True
  20. False ||! False = False
  21.  
  22. -- another or operator
  23. (||#) :: Bool -> Bool -> Bool
  24. False ||# False = False
  25. _ ||# _ = True
  26.  
  27. -- and another or operator
  28. (||@) :: Bool -> Bool -> Bool
  29. False ||@ b = b
  30. True ||@ _ = True
Add Comment
Please, Sign In to add comment