diff options
Diffstat (limited to 'Haskell-book/11/As.hs')
| -rw-r--r-- | Haskell-book/11/As.hs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/Haskell-book/11/As.hs b/Haskell-book/11/As.hs new file mode 100644 index 0000000..744a5fe --- /dev/null +++ b/Haskell-book/11/As.hs @@ -0,0 +1,30 @@ +module As where + +import Data.Char + +isSubseqOf :: (Eq a) => [a] -> [a] -> Bool +isSubseqOf [] _ = True +isSubseqOf _ [] = False +isSubseqOf a@(x:xs) (y:ys) + | x == y = isSubseqOf xs ys + | otherwise = isSubseqOf a ys + +capitalize :: Char -> Char +capitalize x + | (ord x) >= (ord 'a') = (chr ((ord x) - 32)) + | otherwise = x + +capitalizeWords :: String -> [(String, String)] +capitalizeWords text = map f (words text) + where f w@(x:xs) = (w, (capitalize x) : xs) + +capitalizeWord :: String -> String +capitalizeWord (x:xs) = (capitalize x) : xs + +capitalizeParagraph :: String -> String +capitalizeParagraph = it True + where it _ [] = [] + it _ ('.':xs) = '.' : (it True xs) + it y (x:xs) + | (ord x) >= (ord 'a') && (ord x) < (ord 'z') && y = (capitalize x) : (it False xs) + | otherwise = x : (it y xs) |
