Differences

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

Link to this comparison view

fp2024:lab04 [2024/03/26 17:30]
pdmatei created
fp2024:lab04 [2024/03/26 17:32] (current)
pdmatei
Line 25: Line 25:
 </​code>​ </​code>​
  
-**4.2.** ​Implement ​''​size'' ​which returns ​the size of the list:+**4.2.** ​Write down axioms for ''​size ​: IList -> Int'' ​and implement ​the operator in Scala:
 <code scala> <code scala>
 def size(l: IList): Int = ??? def size(l: IList): Int = ???
 </​code>​ </​code>​
  
-**4.3.** Implement ''​append''​ which concatenates two lists:+**4.3.** Implement ''​contains''​ which checks if an element is a member of a list.
 <code scala> <code scala>
-def append(l1IListl2: IList): ​IList = ???+def contains(eIntl: IList): ​Boolean ​= ???
 </​code>​ </​code>​
  
-**4.4.** ​(!) Implement ''​last''​ which returns the last element ​from a list:+**4.4.** Implement ''​max''​ which returns the largest integer ​from a list:
 <code scala> <code scala>
-def last(l: IList): Int = ???+def max(l: IList): Int = ???
 </​code>​ </​code>​
  
-**4.5.** ​(!) Implement ''​reverse''​. There are two different ways to implement reverse (with direct and with tail-end recursion). Try both implementations.+**4.5.** Implement ''​take'' ​which returns a new list containing the first ''​n''​ elements of the original list:
 <code scala> <code scala>
-def reverse(l: IList): IList = ???+def take(n: Int)(l: IList): IList = ???
 </​code>​ </​code>​
  
-**4.6.** Implement ''​contains''​ which checks if an element is a member of a list.+**4.6.** Implement ''​drop''​ which returns ​new list containing the original list without the first ''​n''​ elements:
 <code scala> <code scala>
-def contains(e: Intl: IList): ​Boolean ​= ???+def drop(n: Int)(l: IList): ​IList = ???
 </​code>​ </​code>​
  
-**4.7.** Implement ''​max''​ which returns the largest integer from a list:+**4.7.** Implement ''​append''​ which concatenates two lists:
 <code scala> <code scala>
-def max(l: IList): ​Int = ???+def append(l1: IList, l2: IList): ​IList = ???
 </​code>​ </​code>​
  
-**4.8.** Implement ''​take''​ which returns a new list containing the first ''​n''​ elements of the original ​list:+**4.8.** ​(!) Implement ''​last''​ which returns ​the last element from a list:
 <code scala> <code scala>
-def take(n: Int)(l: IList): ​IList = ???+def last(l: IList): ​Int = ???
 </​code>​ </​code>​
  
-**4.9.** Implement ''​drop'' ​which returns a new list containing the original list without the first ''​n''​ elements:+**4.9.** ​(!) Implement ''​reverse''​. There are two different ways to implement reverse (with direct and with tail-end recursion). Try both implementations.
 <code scala> <code scala>
-def drop(n: Int)(l: IList): IList = ???+def reverse(l: IList): IList = ???
 </​code>​ </​code>​