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

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!
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.
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 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...
C++ Programming 19.2 Operator Overloading practice Write the prototypes and functions to overload the given operators...
C++ Programming 19.2 Operator Overloading practice Write the prototypes and functions to overload the given operators in the code main.cpp //This program shows how to use the class rectangleType. #include <iostream> #include "rectangleType.h" using namespace std; int main() { rectangleType rectangle1(23, 45); //Line 1 rectangleType rectangle2(12, 10); //Line 2 rectangleType rectangle3; //Line 3 rectangleType rectangle4; //Line 4 cout << "Line 5: rectangle1: "; //Line 5 rectangle1.print(); //Line 6 cout << endl; //Line 7 cout << "Line 8: rectangle2: "; //Line...
Write the below code to use HTML and JavaScript. 1. a) Write a JavaScript program to...
Write the below code to use HTML and JavaScript. 1. a) Write a JavaScript program to display the current day and time. b) Write a JavaScript program to print the contents of the current window.   c) Write a JavaScript program where the program takes a random integer between 1 to 10 d) Write a JavaScript program to calculate multiplication and division of two numbers (input from the user). e)Write a JavaScript program to create a new string from a given...
QUESTION 1: Solve the linear programming model given below using the simplex method. Write the primal...
QUESTION 1: Solve the linear programming model given below using the simplex method. Write the primal and dual results from the optimal table you obtained. MAX Z = 10?1 + 20?2 + 5?3 6?1 + 7?2 + 12?3 ≥ 560 5?1 − 3?2 +   x3 ≤ 100 2000?1 + 1000?2 + 1000?3 ≤ 62298 ?1,?2,?3 ≥ 0 IMPORTANT REMINDER ABOUT THE QUESTION SOLUTION: NEW ORDER CALCULATIONS SHOULD BE WRITTEN DETAILED WHEN CREATING THE SYMPLEX TABLES. WHEN THE CALCULATIONS ARE SHOWED AND...
Use two functions below for parts a and b.  ?(?)=??−?  ?(?)=ln(?)+ln(1−?)+3 a) Find the...
Use two functions below for parts a and b.  ?(?)=??−?  ?(?)=ln(?)+ln(1−?)+3 a) Find the stationary points, if any, of the following functions and label them accordingly (local or global minima/maxima or inflection point). b) Characterize the above functions as convex, concave or neither convex nor concave
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT