FP Laboratory 5

From Marek Běhálek Wiki
Revision as of 14:15, 17 September 2019 by Beh01 (talk | contribs)
Jump to navigation Jump to search

List comprehension

Using the list comprehension implement following functions:

  • Create a function that generates a list of all odd numbers in given interval.
oddList :: Int -> Int -> [Int]
  • Create a function that takes a string and converts all characters to upper case letters.
allToUpper :: String -> String
  • Create a function that removes all upper case letters from a string.
removeAllUpper :: String -> String
  • Create functions that computes union and intersection of two sets.
union :: [a] -> [a] -> [a]
intersection :: [a] -> [a] -> [a]

More complex functions

  • Create a function that count the number of occurrences of all characters from a given string.
countThem :: String -> [(Char, Int)]
*Main>countThem "hello hello hello"
[('h',3),('e',3),('l',6),('o',3),(' ',2)]
  • Create a function that generates all combinations of given length from the characters from given string.
combinations :: Int -> String -> [String]
*Main> combinations 3 "abcdef"
["abc","abd","abe",...]