This commit is contained in:
2023-01-12 16:09:38 +00:00
parent 1c9923bb91
commit f76fd627a8
+43
View File
@@ -0,0 +1,43 @@
module StringHelp where
--import Data.Char
import Data.Set (Set)
import qualified Data.Set as Set
isVowel :: Char -> Bool
isVowel x = case x of
'a' -> True
'e' -> True
'i' -> True
'o' -> True
'u' -> True
_ -> False
addIndefiniteArticle :: String -> String
addIndefiniteArticle [] = error "tried to add indefinite article to empty string"
addIndefiniteArticle (x : xs) = genarticle ++ (x : xs)
where
flipexception
| w `Set.member` indefiniteExceptions = not
| otherwise = id
w = head (words (x : xs))
genarticle
| flipexception (isVowel x) = "an "
| otherwise = "a "
indefiniteExceptions :: Set String
indefiniteExceptions =
Set.fromList
[ "one"
, "usual"
, "union"
, "honor"
, "honest"
, "honorable"
, "heir"
, "hourglass"
, "eulogy"
, "united"
, "used"
]