summaryrefslogtreecommitdiff
path: root/Haskell-book/11/As.hs
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2025-12-09 16:32:32 +0100
committerEugen Wissner <belka@caraus.de>2025-12-09 16:32:32 +0100
commit3624c712d72d246f21d4e710cec7c11e052e0326 (patch)
treef385cb51c72a0c5eeb2057609b75f5f8c6c4f272 /Haskell-book/11/As.hs
parentc95abc31d62e296db4f1b537e3de440dd40defd1 (diff)
downloadbook-exercises-3624c712d72d246f21d4e710cec7c11e052e0326.tar.gz
Add the haskell book
Diffstat (limited to 'Haskell-book/11/As.hs')
-rw-r--r--Haskell-book/11/As.hs30
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)