Skip to content

Instantly share code, notes, and snippets.

@bitwombat
Created July 16, 2019 00:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bitwombat/c501b5e72d467851912750fcb2e58581 to your computer and use it in GitHub Desktop.
Save bitwombat/c501b5e72d467851912750fcb2e58581 to your computer and use it in GitHub Desktop.
Ex 2 on Page 447
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