Difference between revisions of "FP Laboratory 4"

From Marek Běhálek Wiki
Jump to navigation Jump to search
(Created page with "== Functions working with lists and tuples == Implement following functions: * Create a function that find the smallest element in the list. Consider input restrictions. <syn...")
 
Line 1: Line 1:
== Functions working with lists and tuples ==
+
== Functions working with lists ==
 +
Implement following functions:
  
Implement following functions:
+
* Create a function that takes first n elements of the list.
 +
<syntaxhighlight lang="Haskell">take :: a -> [a] -> [a]</syntaxhighlight>
 +
* Create a function that takes the remaining list after the first n elements.
 +
<syntaxhighlight lang="Haskell">drop :: a -> [a] -> a</syntaxhighlight>
 
* Create a function that find the smallest element in the list. Consider input restrictions.
 
* Create a function that find the smallest element in the list. Consider input restrictions.
 
<syntaxhighlight lang="Haskell">minimum :: [a] -> a -- Is this right?</syntaxhighlight>
 
<syntaxhighlight lang="Haskell">minimum :: [a] -> a -- Is this right?</syntaxhighlight>
 
* Find all prime divisors of a given number.
 
* Find all prime divisors of a given number.
 
<syntaxhighlight lang="Haskell">divisors :: a -> [a]</syntaxhighlight>
 
<syntaxhighlight lang="Haskell">divisors :: a -> [a]</syntaxhighlight>
 +
 +
== Functions working with lists and tuples ==
 +
 +
Implement following functions:
 
* Create a function that merge two lists into one list of tuples.
 
* Create a function that merge two lists into one list of tuples.
 
<syntaxhighlight lang="Haskell">zipThem:: [a] -> [b] -> [(a,b)]</syntaxhighlight>
 
<syntaxhighlight lang="Haskell">zipThem:: [a] -> [b] -> [(a,b)]</syntaxhighlight>
* Create a function that merge two lists into one list of tuples.
+
* Create a function that compute Cartesian product of two vectors.
<syntaxhighlight lang="Haskell">zipThem:: [a] -> [b] -> [(a,b)]</syntaxhighlight>
+
<syntaxhighlight lang="Haskell">dotProduct :: [a] -> [b] -> [(a,b)]</syntaxhighlight>

Revision as of 11:10, 17 September 2019

Functions working with lists

Implement following functions:

  • Create a function that takes first n elements of the list.
take :: a -> [a] -> [a]
  • Create a function that takes the remaining list after the first n elements.
drop :: a -> [a] -> a
  • Create a function that find the smallest element in the list. Consider input restrictions.
minimum :: [a] -> a -- Is this right?
  • Find all prime divisors of a given number.
divisors :: a -> [a]

Functions working with lists and tuples

Implement following functions:

  • Create a function that merge two lists into one list of tuples.
zipThem:: [a] -> [b] -> [(a,b)]
  • Create a function that compute Cartesian product of two vectors.
dotProduct :: [a] -> [b] -> [(a,b)]