numberOfPrefix :: String -> [String] -> Int
numberOfPrefix a b = numPrefixAux a b 0
where
numPrefixAux _ [] n = n
numPrefixAux a (b:bs) n =
| isPrefix a b = numPrefixAux a bs (n+1)
| otherwise = numPrefixAux a bs n
numberOfSubstringOcurrence :: String -> String -> Int
numberOfSubstringOcurrence a b = numSubstringOcurrenceAux a b 0
where
numSubstringOcurrenceAux _ [] n = n
numSubstringOcurrenceAux a b n =
| isPrefix a b = numSubstringOcurrenceAux a (drop (length a) b) (n+1)
| otherwise = numSubstringOcurrenceAux a (tail b) n
numberOfPrefixes :: [String] -> [String] -> [(String,Int)]
numberOfPrefixes l a = numberOfPrefixesAux l a []
where
numberOfPrefixesAux [] _ l = l
numberOfPrefixesAux (h:t) a l =
numberOfPrefixesAux t a ((h,(numberOfPrefix h a)):l)
numberOfSubstringOcurrences :: [String] -> String -> [(String,Int)]
numberOfSubstringOcurrences l a = numSubstringOcurrencesAux l a []
where
numSubstringOcurrencesAux [] _ l = l
numSubstringOcurrencesAux (h:t) a l =
numSubstringOcurrencesAux t a ((h,(numberOfPrefix h a)):l)