Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {-# LANGUAGE ViewPatterns, PatternSynonyms #-}
- import Control.Arrow
- import Data.List (uncons)
- unsnoc :: [a] -> Maybe ([a], a)
- unsnoc [] = Nothing
- unsnoc [x] = Just ([], x)
- unsnoc (x:xs) = (fmap.first) (x:) (unsnoc xs)
- pattern xs :< x <- (unsnoc -> Just (xs,x)) where
- xs :< x = xs ++ [x]
- pattern x :> xs <- (uncons -> Just (x,xs)) where
- x :> xs = x : xs
- palindrome [] = True
- palindrome [x] = True
- palindrome (x:>xs:<y) = x == y && palindrome xs
Add Comment
Please, Sign In to add comment