Guest User

Untitled

a guest
Jul 16th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. mapAll :: (a -> Maybe a) -> [a] -> Maybe [a]
  2. mapAll _ [] = Just []
  3. mapAll f (x:xs) = case f x of
  4. Just x' -> case mapAll f xs of
  5. Just xs' -> Just (x':xs')
  6. Nothing -> Nothing
  7. Nothing -> Nothing
  8.  
  9. mapOne :: (a -> Maybe a) -> [a] -> Maybe [a]
  10. mapOne _ [] = Nothing
  11. mapOne f (x:xs) = case f x of
  12. Just x' -> Just (x':xs)
  13. Nothing -> case mapOne f xs of
  14. Just xs' -> Just (x:xs')
  15. Nothing -> Nothing
  16.  
  17. mapSome :: (a -> Maybe a) -> [a] -> Maybe [a]
  18. mapSome _ [] = Nothing
  19. mapSome f (x:xs) = case f x of
  20. Just x' -> case mapSome f xs of
  21. Just xs' -> Just (x':xs')
  22. Nothing -> Just (x':xs)
  23. Nothing -> case mapSome f xs of
  24. Just xs' -> Just (x:xs')
  25. Nothing -> Nothing
Add Comment
Please, Sign In to add comment