Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
fp2023:lab03 [2023/03/15 08:52]
pdmatei created
fp2023:lab03 [2023/03/15 13:06] (current)
bogdan.butnariu added offset for Line2D Functions
Line 5: Line 5:
   * implement **curry** and **uncurry** functions, and how they should be properly used (review lecture).   * implement **curry** and **uncurry** functions, and how they should be properly used (review lecture).
  
-**3.1.** Define the function ''​foldWith''​ which uses an operation ''​op'',​ and an initial value ''​b''​ to reduce a range of integers to a value. For instance, given that ''​op''​ is addition (+), the result of folding the range 1 to 3 with ''​b = 0''​ will be ''​((0 + 1) + 2 + 3 = 6''​. ''​foldWith''​ should be curried (it will take the operation and return another function which expects the bounds). Note that ''​foldWith''​ is **curry**.+**3.1.** Define the function ''​foldWith''​ which uses an operation ''​op'',​ and an initial value ''​b''​ to reduce a range of integers to a value. For instance, given that ''​op''​ is addition (+), the result of folding the range 1 to 3 with ''​b = 0''​ will be ''​( ( 0 + 1 ) + 2 + 3 = 6''​. ''​foldWith''​ should be curried (it will take the operation and return another function which expects the bounds). Note that ''​foldWith''​ is **curry**.
  
 <code scala> <code scala>
Line 50: Line 50:
 <code scala> <code scala>
 type Line2D = Int => Int type Line2D = Int => Int
-def translateOx(l:​ Line2D): Line2D = ???+def translateOx(offset: Int)(l: Line2D): Line2D = ???
 </​code>​ </​code>​
  
 **3.9.** (!) Write a function which takes a Line2D and translates it up on the Oy axis by a given offset. **3.9.** (!) Write a function which takes a Line2D and translates it up on the Oy axis by a given offset.
 <code scala> <code scala>
-def translateOy(l:​ Line2D): Line2D = ???+def translateOy(offset: Int)(l: Line2D): Line2D = ???
 </​code>​ </​code>​