Edit this page Backlinks This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ===== 5. Processing using higher-order functions ===== The following is an input test. You can add more examples to it: <code haskell> l = ["matei@gmail.com", "mihai@gmail.com", "tEst@mail.com", "email@email.com", "short@ax.ro"] </code> Use ''map'', ''foldr''/''foldl'', instead of recursive functions. Wherever possible, use functional composition and closures. 5.1. Replace uppercases with lowercases from emails. (Do **not** use recursion). To be able to use character functions from the library, add ''import Data.Char'' at the beginning of the program. Use the Internet to find the appropriate character function. <code haskell> rem_upper l = </code> 5.2. Write a function which removes emails longer than a given size. Use anonymous functions in your implementation, then think about how you can replace them by a functional composition of more basic functions. **Hint:** Write your code in steps. Start with the basic idea, then think about how you can write it better and cleaner. <code haskell> longer :: Int -> [String] -> [String] longer x = </code> 5.3. Count the number of emails longer than 12 characters. Use a fold, anonymous functions and functional composition. <code haskell> howmany l = </code> 5.4. Split the list between first names and email domains. What ingredients (auxiliary functions) are necessary? Use either a fold or a tail-recursive function in your implementation. Example: ''names_emails ["matei@email.com"] = [ ["matei", "email.com"] ]''. <code haskell> names_emails :: [String] -> [[String]] names_emails l = </code> 5.5. Identify the list of the employed domain names (e.g. ''gmail.com''). Remove duplicates. Use no recursion and no additional prelude function apart from ''head'' and ''tail''. **Hint** think about the sequence of basic operations you want to perform and assemble them using functional composition. <code haskell> domains :: [String] -> [String] domains = </code> (!) 5.6. In some previous exercise you have, most likely, implemented a split function using ''foldr''. Implement one with ''foldl''. **Hint:** use an example together with the ''foldl'' implementation to figure out what the accumulator should do. <code haskell> splitl :: String -> [String] splitl = </code> 5.7. Write a function which extracts the domains from emails, without the dot part. (e.g. ''gmail''). Generalise the previous function ''splitl'' to ''splitBy:: Char -> String -> [String]'', and use it each time necessary, in your implementation. **Hint**: Wherever you want to mix pattern matching with guards, start with the patterns first. <code haskell> domain :: [String] -> [String] domain = </code>