0votos

Traductor de 'Pig latin' en Haskell

por josejuan hace 3 años

Una cualquiera (no queda claro como tratar las palabras tras un símbolo).

El pig latin es un juego con el idioma inglés. Buenos días en pig latin se dice 'oodgay orningmay'.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import Data.Char 
 
isVocal c = c `elem` "aeiouyAEIOUY" 
isConsonant c = isLetter c && not (isVocal c) 
 
wordSplit f xs = (takeWhile f xs, dropWhile f xs) 
 
wordPig [] = [] 
wordPig xs@(x:_) 
  | isVocal x     = xs ++ "yay" 
  | isConsonant x = if isLower x then s:ss else toUpper s:map toLower ss 
  | otherwise     = xs 
  where (s:ss) = d ++ t ++ "ay" 
        (t, d) = wordSplit isConsonant xs 
 
wordPig' xs = wordPig t ++ d 
              where (t, d) = wordSplit isLetter xs 
 
textPig = unwords . map wordPig' . words 
 
 
 
 
 
 
-- por ejemplo 
 
shakespeare = "Shakespeare was born and brought up in Stratford-upon-Avon. \ 
               \At the age of 18, he married Anne Hathaway, with whom he had \ 
               \three children: Susanna, and twins Hamnet and Judith. Between \ 
               \1585 and 1592, he began a successful career in London as an \ 
               \actor, writer, and part-owner of a playing company called the \ 
               \Lord Chamberlain's Men, later known as the King's Men. He appears \ 
               \to have retired to Stratford around 1613 at age 49, where he died \ 
               \three years later. Few records of Shakespeare's private life \ 
               \survive, and there has been considerable speculation about such \ 
               \matters as his physical appearance, sexuality, religious beliefs, \ 
               \and whether the works attributed to him were written by others." 
 
{- 
*Main Data.Char Data.List> :l piglatin.hs  
[1 of 1] Compiling Main             ( piglatin.hs, interpreted ) 
Ok, modules loaded: Main. 
*Main Data.Char Data.List> textPig shakespeare  
"Akespeareshay asway ornbay andyay oughtbray upyay inyay Atfordstray-upon-Avon. Atyay ethay ageyay ofyay 18, ehay arriedmay Anneyay Athawayhay, ithway omwhay ehay adhay eethray ildrenchay: Usannasay, andyay instway Amnethay andyay Udithjay. Etweenbay 1585 andyay 1592, ehay eganbay ayay uccessfulsay areercay inyay Ondonlay asyay anyay actoryay, iterwray, andyay artpay-owner ofyay ayay ayingplay ompanycay alledcay ethay Ordlay Amberlainchay's Enmay, aterlay ownknay asyay ethay Ingkay's Enmay. Ehay appearsyay otay avehay etiredray otay Atfordstray aroundyay 1613 atyay ageyay 49, erewhay ehay iedday eethray yearsyay aterlay. Ewfay ecordsray ofyay Akespeareshay's ivatepray ifelay urvivesay, andyay erethay ashay eenbay onsiderablecay eculationspay aboutyay uchsay attersmay asyay ishay ysicalphay appearanceyay, exualitysay, eligiousray eliefsbay, andyay etherwhay ethay orksway attributedyay otay imhay ereway ittenwray ybay othersyay." 
*Main Data.Char Data.List>  
-} 

Comenta la solución

Tienes que identificarte para poder publicar tu comentario.