Created
July 16, 2019 00:19
-
-
Save bitwombat/c501b5e72d467851912750fcb2e58581 to your computer and use it in GitHub Desktop.
Ex 2 on Page 447
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Page447 where | |
import Data.Char | |
capitalizeWord :: String -> String | |
capitalizeWord (c:cs) = toUpper c : cs | |
endsWithPeriod :: String -> Bool | |
endsWithPeriod word = last word == '.' | |
capitalizeParagraph :: String -> String | |
capitalizeParagraph para = unwords (go (words para) True) | |
where | |
go [] _ = [] | |
go (word:words) capIt = wordCapped : go words (endsWithPeriod word) | |
where wordCapped = if capIt then (capitalizeWord word) else word |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment