Question

Write a Haskell function piglatinize that returns a word into its piglatin form: if it begins...

  1. Write a Haskell function piglatinize that returns a word into its piglatin form: if it begins with a vowel, add to the end "yay", else move non-vowels to the end of the string until a vowel is at the front and then add to the end "ay". The word arguments are guaranteed to have a vowel (a, e, i, o, or u) and not begin with the letter y.
    piglatinize :: String -> String
0 0
Add a comment Improve this question Transcribed image text
Answer #1

piglatinize :: String -> String
piglatinize [] = []
piglatinize (a:[]) = [a]
piglatinize a
    | head a == 'a' || head a == 'e' || head a == 'i' || head a == 'o' || head a == 'u'    = a ++ "yay"
    | otherwise = piglatinize' a ++ "ay"

piglatinize' :: String -> String
piglatinize' (a:b)
    | a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u'    = (a:b)
    | otherwise = piglatinize' (x)
where x = b++[a]

Add a comment
Know the answer?
Add Answer to:
Write a Haskell function piglatinize that returns a word into its piglatin form: if it begins...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Pig Latin program using Linked Lists C++

    Write a program that prompts the user to input a string and then outputs the string in the pig Latin form. The rules for converting a string into pig Latin form are asfollows:a. If the string begins with a vowel, add the string "-way" at the end of the string. for example, the pig Latin form of the string "eye" is "eye-way".b. If the string does not begin with a vowel, first ass "-" at the end of the string....

  • In C Sixth: Pig Latin (10 Points) For this part of the assignment, you will need...

    In C Sixth: Pig Latin (10 Points) For this part of the assignment, you will need to write a program that reads an input string representing a sentence, and convert it into pig latin. We'll be using two simple rules of pig latin: 1. If the word begins with a consonant then take all the letters up until the first vowel and put them at the end and then add "ay" at the end. 2. If the word begins with...

  • Haskell Programming 2. Returns the plural of a word by adding "s' unless the word ends...

    Haskell Programming 2. Returns the plural of a word by adding "s' unless the word ends in "y", in which can you remove the "y" and add "ies" 3. Write a function that takes two lists and returns a list of only those elements that appear in both lists. 4. Write a function that takes a list and an element and returns the number of times the element appears in the list. 5. Remove the leading spaces from a string...

  • Write the Java code for the class WordCruncher. Include the following members:

    **IN JAVAAssignment 10.1 [95 points]The WordCruncher classWrite the Java code for the class WordCruncher. Include the following members:A default constructor that sets the instance variable 'word' to the string "default".A parameterized constructor that accepts one String object as a parameter and stores it in the instance variable. The String must consist only of letters: no whitespace, digits, or punctuation. If the String parameter does not consist only of letters, set the instance variable to "default" instead. (This restriction will make...

  • In C please Pig latin has two very simple rules: If a word starts with a...

    In C please Pig latin has two very simple rules: If a word starts with a consonant move the first letter(s) of the word, till you reach a vowel, to the end of the word and add "ay" to the end. have ➞ avehay cram ➞ amcray take ➞ aketay cat ➞ atcay shrimp ➞ impshray trebuchet ➞ ebuchettray If a word starts with a vowel add "yay" to the end of the word. ate ➞ ateyay apple ➞ appleyay...

  • String variables/Selection & loop Write a complete Java program which prompts the user for a sentence on one line wh...

    String variables/Selection & loop Write a complete Java program which prompts the user for a sentence on one line where each word is separated by one space, reads the line into one String variable using nextline(), converts the string into Ubbi dubbi and displays the translated sentence. Ubbi dubbi works by adding ub before each vowel sound in a syllable. For example, hello becomes hubellubo. The word speak has the vowel sound ea, so in Ubbi dubbi it becomes spubeak....

  • Write a function palcheck (char word II) which takes a C-style string word (or a C++...

    Write a function palcheck (char word II) which takes a C-style string word (or a C++ string word if you wish) and returns or false depending on whether or not the string is a palindrome. (A palindrome is a string which reads the same backwards and forwards. Some classic example of palindromes are radar, racecar, toot, deed, bib, civic, redder and madam.) Use your function from part (a) in a complete C++ program which, for each small letter 'a' through...

  • Haskell Functional Programming Language: Write a function nestedParens that takes a string argument and returns true...

    Haskell Functional Programming Language: Write a function nestedParens that takes a string argument and returns true if it is a nesting of zero or more pairs of parentheses, e.g. "((()))" should return True ; "()()" or "(()))" should return False . Use recursion for this problem. nestedParens :: String -> Bool

  • sorted vowels Write a function that returns true if the vowels in the input string A...

    sorted vowels Write a function that returns true if the vowels in the input string A appear in non-decreasing order and false otherwise. You can assume this function is not case sensitive. If the string does not contain any vowels, it must return true. bool sorted_vowels (const char A)

  • /** * Returns the result of converting s to "Pig Latin". Convert a string s to...

    /** * Returns the result of converting s to "Pig Latin". Convert a string s to Pig Latin by using the following rules: * * (1) If s contains no vowels, do nothing to it. * * (2) Otherwise, if s starts with a vowel, append "way" to the end. * * (3) Otherwise, move everything up to (but not including) the first vowel to the end and add "ay". * * For example, "hello" converts to "ellohay", "small" converts...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT