Created
July 9, 2013 02:40
-
-
Save yucombinator/5954276 to your computer and use it in GitHub Desktop.
pig latin translator for haskell
This file contains 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
{-# LANGUAGE CPP, TemplateHaskell #-} | |
----------------------------------------------------------------------------- | |
-- | |
-- Module : pigLatin | |
-- Copyright : | |
-- License : AllRightsReserved | |
-- | |
-- Maintainer : Yu Chen Hou | |
-- Stability : | |
-- Portability : | |
-- | |
-- | | |
-- | |
----------------------------------------------------------------------------- | |
module Main ( | |
main | |
) where | |
import Control.Monad (unless) | |
import Data.List (stripPrefix) | |
import System.Exit (exitFailure) | |
-- pigLatin | |
main = do | |
putStrLn ("Enter message to translate: ") | |
s <- getLine | |
if null s | |
then return () | |
else do | |
putStrLn $ unwords (map pigLatin (words s)) | |
main | |
-- Simple function to translate into pig latin | |
pigLatin :: String -> String | |
pigLatin [] = "" | |
pigLatin str = if (isVowel (head str)) | |
then str ++ "yay" | |
else if (not (isVowel (head(tail(str))))) | |
then ((tail(tail str))) ++ [(head str)] ++ [(head(tail str))] ++ "ay" | |
else (tail str)++[(head str)]++"ay" | |
--Check if string is a vowel | |
isVowel :: Char -> Bool | |
isVowel v = v `elem`['a','e','i','o','u'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment