Difference between revisions of "FP Laboratory 5"

From Marek Běhálek Wiki
Jump to navigation Jump to search
(Created page with "== High-order functions == == More complex functions == * Create a function that count the number of occurrences of all characters from a given string. <syntaxhighlight la...")
 
Line 1: Line 1:
== High-order functions ==
+
== List comprehension ==
 +
Using the list comprehension implement following functions:
 +
* Create a function that generates a list of all odd numbers in given interval.
 +
<syntaxhighlight lang="Haskell">oddList :: Int -> Int -> [Int]</syntaxhighlight>
 +
* Create a function that takes a string and converts all characters to upper case letters.
 +
<syntaxhighlight lang="Haskell">allToUpper :: String -> String</syntaxhighlight>
 +
* Create a function that removes all upper case letters from a string.
 +
<syntaxhighlight lang="Haskell">removeAllUpper :: String -> String</syntaxhighlight>
 +
* Create functions that computes union and intersection of two sets.
 +
<syntaxhighlight lang="Haskell">
 +
union :: [a] -> [a] -> [a]
 +
intersection :: [a] -> [a] -> [a]
 +
</syntaxhighlight>
  
 +
== More complex functions ==
  
 
== More complex functions ==
 
 
* Create a function that count the number of occurrences of all characters from a given string.  
 
* Create a function that count the number of occurrences of all characters from a given string.  
 
<syntaxhighlight lang="Haskell">countThem :: String -> [(Char, Int)]</syntaxhighlight>
 
<syntaxhighlight lang="Haskell">countThem :: String -> [(Char, Int)]</syntaxhighlight>

Revision as of 14:09, 17 September 2019

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)]