Question
Count occurrences of an element in a list (Answer must be in Haskell Programming language) For this problem, youll write a list-processing function that consumes
Count occurrences of an element in a list (Answer must be in Haskell Programming language)
For this problem, youll write a list-processing function thatconsumesa list, but just produces an integer. It should count how many times a particular element appears in a list. Here are some examples:
ghci> countOccurences 5 [1..10]
1
ghci> countOccurences 5 [1,5,2,5,3,5,7,5]
4
ghci> countOccurences 'a' "abracadabra"
5
ghci> countOccurences 'o' "xylophone"
2
You can either write it recursively by pattern-matching on the list, or you can use a combination of existing functions.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started