Question

In HASKELL Write a function that will delete leading white space from a string. cutWhitespace ["...

In HASKELL

Write a function that will delete leading white space from a string.

cutWhitespace [" x","y"," z"]

ans: ["x","y","z"]

You are allowed to use any higher order function/List Comprehension(if you want to use) to solve this problem.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

removeLeadingWhiteSpace (x:xs)
| x == ' ' = removeLeadingWhiteSpace(xs)
| otherwise = x:xs

cutSpace arr = map removeLeadingWhiteSpace arr

*Main> cutSpace CX, Y, Z] Main
Add a comment
Know the answer?
Add Answer to:
In HASKELL Write a function that will delete leading white space from a string. cutWhitespace ["...
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
  • 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 a function in HASKELL to reverse a string (or list) without using the built-in reverse...

    Write a function in HASKELL to reverse a string (or list) without using the built-in reverse function.           Example:           Hello as olleh or [1,3,4,5] as [5,4,3,1].

  • 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

  • All of the problems must be done in Haskell. You may download a local IDE or...

    All of the problems must be done in Haskell. You may download a local IDE or use [this website.][https://repl.it/languages/haskell]. You are not allowed any functions that trivialize a problem! Here are some examples of lists you can test your solutions on: let list1 = [5, 10, 15, 20, 25, 30] let list2 = [50, 100, 150, 200, 250, 300] Write a function that returns the maximum value in a list. Write a function that returns the nth element in the...

  • Haskell Define function-divisors that receives a number and returns a list of all divisors of that...

    Haskell Define function-divisors that receives a number and returns a list of all divisors of that number.For example, if the input is 20, then the output would be[1,2,4,5,10,20]. You may use list comprehension, list ranges, and function mod for this purpose.Hint:Given numbern, consider all numbers from 1 ton, and then keep only the ones that dividen.

  • In Haskell: Write a recursive function fibonacci that computes the n-th Fibonacci number. fibonacci :: Int...

    In Haskell: Write a recursive function fibonacci that computes the n-th Fibonacci number. fibonacci :: Int -> Int Write a recursive function myProduct that multiplies all the numbers in a list. myProduct :: [Integer] -> Integer Using the technique of List Comprehension write a function that would remove even numbers from a list of lists. For Example: given input: [[1,2,3,4], [6,3,45,8], [4,9,23,8]] expected output: [[1,3], [3,45],[9,23]]. Show how the library function replicate :: Int -> a-> [a] that produces a...

  • Write a function in Java Script that accepts a string. The function takes the last digit...

    Write a function in Java Script that accepts a string. The function takes the last digit of the ASCII code and returns a string of digits sorted in ascending order E.G. function("zDbc") returns “2,8,8,9” (z => 122, D=>68, b=>98, c=>99) ....i am not allowed to use any of the built-in functions

  • Python3: Write the function longestSubpalindrome(s), that takes a string s and returns the longest palindrome that...

    Python3: Write the function longestSubpalindrome(s), that takes a string s and returns the longest palindrome that occurs as consecutive characters (not just letters, but any characters) in s. so longestSubpalindrome("ab-4-be!!!") returns "b-4-b".If there is a tie, return the lexicographically larger value -- in Python, a string s1 is lexicographically greater than a string s2 if (s1 > s2). So: longestSubpalindrome("abcbce") returns "cbc", since ("cbc" > "bcb"). Note that unlike the previous functions, this function is case-sensitive (so "A" is not...

  • Please use Haskell, thank you! For this question, you will implement (under specific constraints) a recursive...

    Please use Haskell, thank you! For this question, you will implement (under specific constraints) a recursive function in Haskell that takes a list of characters as an argument and returns a list that contains only every third element from the argument list in the same order. As a clarifying example, this function, when passed the argument list “ABCDEFGHIJKLMNO”, should return the list “ CFILO”. It should also be noted that your function must work (i.e., not terminate with an error)...

  • Please solve this problem using Python Write a quicksort method that accept a list of numbers...

    Please solve this problem using Python Write a quicksort method that accept a list of numbers and use list comprehension to construct the method. Note that you need to sort the numbers in descending order . You MUST use List Comprehension to do the sorting Your program should contain the function with format shown as below: def quicksort(a): # Your codes here. Use List Comprehension and return the result.

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