Skip to content

Instantly share code, notes, and snippets.

@yucombinator
Created July 9, 2013 02:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save yucombinator/5954276 to your computer and use it in GitHub Desktop.
Save yucombinator/5954276 to your computer and use it in GitHub Desktop.
pig latin translator for haskell
{-# 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