Guest User

Untitled

a guest
Oct 19th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. {-# LANGUAGE ViewPatterns, PatternSynonyms #-}
  2.  
  3. import Control.Arrow
  4. import Data.List (uncons)
  5.  
  6. unsnoc :: [a] -> Maybe ([a], a)
  7. unsnoc [] = Nothing
  8. unsnoc [x] = Just ([], x)
  9. unsnoc (x:xs) = (fmap.first) (x:) (unsnoc xs)
  10.  
  11. pattern xs :< x <- (unsnoc -> Just (xs,x)) where
  12. xs :< x = xs ++ [x]
  13.  
  14. pattern x :> xs <- (uncons -> Just (x,xs)) where
  15. x :> xs = x : xs
  16.  
  17. palindrome [] = True
  18. palindrome [x] = True
  19. palindrome (x:>xs:<y) = x == y && palindrome xs
Add Comment
Please, Sign In to add comment