Question

In: Computer Science

HASKELL PROGRAMMING Use the functions concatenate AND concatList to write the functions below: 1) WRITE the...

HASKELL PROGRAMMING

Use the functions concatenate AND concatList to write the functions below:

1) WRITE the function: concatStringsUsingDelimiter (can use fold instruction and a lambda expression to define)

Sample run = *Main> concatStringsUsingDelimiter '#' ["The", "quick" , "boy" , "ran."]

"The#quick#boy#ran.#"

2) WRITE the function: unconcatStringWithDelimiter (inverse of function above. can use haskell's let construct and/or where construct)

Sample run = *Main> unconcatStringWithDelimiter '#'

"The#quick#boy#ran.#"

["The" , "quick" , "boy" , "ran."]

SIDE NOTE: Please write comments describing each function and a type definition for each function preceding the function definition

Solutions

Expert Solution

-- function signature taking delimitor and array and returns string sequence
concatStringsUsingDelimiter :: [a] -> [[a]] -> [a]
-- return empty string if there is input array is empty
concatStringsUsingDelimiter s [] = []
-- returns single element if the input is also a single
concatStringsUsingDelimiter s [x] = x
concatStringsUsingDelimiter s (x:xs) = x ++ s ++ (concatStringsUsingDelimiter s xs)



-- function signature taking delimitor and array and returns Array sequence
unconcatStringWithDelimiter :: Char -> String -> [String]
-- returns empty array if the input string is empty
unconcatStringWithDelimiter _ "" = [];
-- here is the mail logic which we remove the delimitor elements from the given the string makes an array out of it
unconcatStringWithDelimiter delimiterChar inputString = foldr f [""] inputString
  where f :: Char -> [String] -> [String]
        f currentChar allStrings@(partialString:handledStrings)
          | currentChar == delimiterChar = "":allStrings
          | otherwise = (currentChar:partialString):handledStrings 


Related Solutions

Write a function to concatenate two strings using pointer notation
Write a function to concatenate two strings using pointer notation
FOR ARDUINO PROGRAMMING; WRITE CODE TO FIT THE BELOW REQUIREMENTS; 1. LED 1 TURNS ON AND...
FOR ARDUINO PROGRAMMING; WRITE CODE TO FIT THE BELOW REQUIREMENTS; 1. LED 1 TURNS ON AND STAYS ON THE ENTIRE TIME THE BOARD IS RUNNING EXCEPT AT 30 SECOND INTERVALS THEN LED 1 TURNS OFF AND BACK ON 2. LED 2 TURNS ON IN LIGHT CONDITIONS AND OFF IN DARK CONDITION THANK YOU!
1. How do I write a query that displays the name (concatenate the first name, middle...
1. How do I write a query that displays the name (concatenate the first name, middle initial, and last name), date of birth, and age for all students? Show the age with no decimal places, and only include those students who are 21 or older. Order by age, as shown below: (Hint: Use the TRUNC function. The ages may be different, depending on the date that the query is run.) SELECT S_FIRST || ' ' || S_MI || ' '...
Use Python for this quetions: Write a python functions that use Dictionary to: 1) function name...
Use Python for this quetions: Write a python functions that use Dictionary to: 1) function name it addToDictionary(s,r) that take a string and add it to a dictionary if the string exist increment its frequenc 2) function named freq(s,r) that take a string and a record if the string not exist in the dictinary it return 0 if it exist it should return its frequancy.
In Object Oriented programming C++ : Write the appropriate functions for Student to neatly display a...
In Object Oriented programming C++ : Write the appropriate functions for Student to neatly display a Student, and then finally GPA. Have items neatly line up in columns. I need help creating a derived class called student that finds GPA (between 0.0 and 4.0) and credits completed (between 0 and 199).
USE C PROGRAMMING, call all functions in main, and use a 2 by 3 2d array...
USE C PROGRAMMING, call all functions in main, and use a 2 by 3 2d array to test, thanks. get_location_of_min This function takes a matrix as a 2-D array of integers with NUM_COLS width, the number of rows in the matrix and two integer pointers. The function finds the location of the minimum value in the matrix and stores the row and column of that value to the memory location pointed to by the pointer arguments. If the minimum value...
FOR ARDUINO PROGRAMMING; WRITE CODE TO FIT THE BELOW REQUIREMENTS 1. LED 3 TURNS ON IN...
FOR ARDUINO PROGRAMMING; WRITE CODE TO FIT THE BELOW REQUIREMENTS 1. LED 3 TURNS ON IN DARK CONDITIONS AND OFF IN LIGHT CONDITIONS 2. LED 4 TURNS ON WITH FIRST BUTTON PRESS AND STAYS ON UNTIL A SECOND BUTTON PRESS
Write an essay about the primary use of the Programming Languages
Write an essay about the primary use of the Programming Languages
Write a Haskell function combine :: Int -> Int -> Int -> Int with the following...
Write a Haskell function combine :: Int -> Int -> Int -> Int with the following behavior: • When x, y, and z all correspond to digit values (i.e., integers between 0 and 9, inclusive), combine x y z returns the integer given by the sequence of digits x y z. (That is, x is treated as the digit in the hundreds place, y is treated as the digit in the tens place, and z is treated as the digit...
Using the string functions below, write new functions to do the following, and test them in...
Using the string functions below, write new functions to do the following, and test them in your main() function: Determine whether the first or last characters in the string are any of the characters a, b, c, d, or e. Reverse a string Determine whether a string is a palindrome (spelled the same way forward or backward FUNCTIONS REFERENCE: string myString = "hello"; // say we have a string… // … we can call any of the following // string...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT