Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
pp:2024:scala:l02 [2025/03/05 10:43]
pdmatei [2.3 Curry vs Uncurry]
pp:2024:scala:l02 [2025/03/05 10:47] (current)
pdmatei
Line 31: Line 31:
 **2.1.4** Write a function ''​realtrycatch''​ where t and c take no parameters and produce a result upon evaluation. If an error occurs (try function returns 0), the catch function will be called instead. **2.1.4** Write a function ''​realtrycatch''​ where t and c take no parameters and produce a result upon evaluation. If an error occurs (try function returns 0), the catch function will be called instead.
 <code scala> <code scala>
-def realtrycatch(t : => Int, c: => Int): Int  = {+def realtrycatch(t : => Int, c: => Int): Int = {
    ???    ???
 } }
Line 37: Line 37:
  
 ===== 2.2 Custom high order functions ===== ===== 2.2 Custom high order functions =====
 +
 **2.2.1** Define the function ''​foldWith''​ which uses an operation ''​op''​ 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 will be 1+2+3=6. ''​foldWith''​ should be curried (it will take the operation and return another function which expects the bounds). **2.2.1** Define the function ''​foldWith''​ which uses an operation ''​op''​ 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 will be 1+2+3=6. ''​foldWith''​ should be curried (it will take the operation and return another function which expects the bounds).
 <code scala> <code scala>
Line 55: Line 56:
 <code scala> <code scala>
 def foldMap(op: (Int,Int) => Int, f: Int => Int)(start: Int, stop: Int): Int = ??? def foldMap(op: (Int,Int) => Int, f: Int => Int)(start: Int, stop: Int): Int = ???
-</+</code>
-ode>+
  
 ===== 2.3 Curry vs Uncurry ===== ===== 2.3 Curry vs Uncurry =====
Line 72: Line 72:
   else z   else z
 } }
-</ +</​code>​
-code>+
  
 ===== 2.4 Function transformations ===== ===== 2.4 Function transformations =====