Skip to content

Instantly share code, notes, and snippets.

@Qata
Last active February 4, 2017 08:51
Show Gist options
  • Save Qata/d9bd97aa60d224d13d2716df96b3d0b6 to your computer and use it in GitHub Desktop.
Save Qata/d9bd97aa60d224d13d2716df96b3d0b6 to your computer and use it in GitHub Desktop.
import Data.String.Utils
import Data.List
import Data.Char
import Data.Maybe
import System.Environment
main :: IO ()
main = do
strings <- getArgs
mapM_ (putStrLn . pronounify) strings
capitalise :: [Char] -> [Char]
capitalise x = (toUpper $ head x) : tail x
isCapitalised :: [Char] -> Bool
isCapitalised x = isUpper $ head x
forEachPronoun :: [Char] -> [Char] -> [[Char]]
forEachPronoun x y =
let
orify a b = a ++ " or " ++ b
commaify a b = a ++ ", " ++ b
orifiedPronouns = [orify x y, orify y x]
commaedPronouns = [commaify x y, commaify y x]
combinedPronouns = orifiedPronouns ++ commaedPronouns
in
combinedPronouns ++ map capitalise combinedPronouns
pronouns =
[ (forEachPronoun "his" "her", "their")
, (forEachPronoun "his" "hers", "theirs")
, (forEachPronoun "himself" "herself", "themself")
, (forEachPronoun "she" "he", "they")
, (forEachPronoun "him" "her", "them")
]
pronounify :: [Char] -> [Char]
pronounify s =
let
replacementF r s p
| isCapitalised p = replace p (capitalise r) s
| otherwise = replace p r s
replacePronoun (ps, r) s = foldl (replacementF r) s ps
in
foldl (flip replacePronoun) s pronouns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment