Guest User

Untitled

a guest
Jan 9th, 2018
48
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import Data.Char
  2. import Data.List
  3. import qualified Data.Set as Set
  4.  
  5. vowel x = elem x "aeiou"
  6.  
  7. toPigLatin :: String -> String
  8. toPigLatin word
  9.     | vowel (head word) = word ++ "ay"
  10.     | otherwise = let (v, c) = span (not . vowel) word in
  11.                                 if c == "" then word
  12.                                 else c ++ v ++ "ay"
  13.  
  14.  
  15. pigExists :: String -> Set.Set String -> Bool
  16. pigExists word set = Set.member (toPigLatin word) set
  17.  
  18. main :: IO ()
  19. main = do
  20.     allWords <- (((map.map) toLower) . words) <$> readFile "/tmp/linuxwords" --https://users.cs.duke.edu/~ola/ap/linuxwords
  21.     let pigHits = filter (\word -> pigExists word (Set.fromList allWords)) allWords
  22.     print $ pigHits
RAW Paste Data