Assignment 1: Introduction to Scala

Description

The goal of this assignment is to familiarize yourself with Scala. We have provided a basic tutorial on Scala to help this process along, which focuses specifically on points which are directly relevant to CS162.

Download the template code and tutorial below. As a first step, you should go through this tutorial and fill in missing portions, marked by ??? snippets, as needed to get the code to run correctly. With the tutorial, you should start with introduction.html, then proceed through the Scala files in order (starting with 0, then 1, etc.). Once you've completed the tutorial, there are three problems in SmallerProblems.scala which you must solve. Finally, you need to fill in the missing implementations in MyList.scala. More complete directions are contained in the aforementioned files.

Specific to Problem 2 in SmallerProblems.scala, the image here may be of use in understanding exactly how the traversal is performed:

Grading

A breakdown of the grade follows (out of 60 points):

  • Completing the missing pieces of the tutorial
  • Problem 1 of SmallerProblems.scala
  • Problem 2 of SmallerProblems.scala
  • Problem 3 of SmallerProblems.scala
  • foldLeft and foldRight in MyList.scala
  • filter and map in MyList.scala
  • flatMap in MyList.scala
  • All other missing pieces of MyList.scala

Downloads

Assignment 1 (zip)

Deliverables

You must turnin all files with the .scala extension. The command below should be sufficient:
turnin assign1@cs162 MyList.scala SmallerProblems.scala tutorial/*.scala

Note

Do not let the low score of the tutorial fool you: it is expected that the tutorial will take a significant amount of time. Getting the remaining pieces to work without having gone through the tutorial will be extremely challenging.

As a reminder: with the exception of vars we have introduced, you may not use any mutable state. That is, you cannot introduce new vars or any mutable data structures; you only modify the few existing vars that we've provided. This is to encourage you to think in a functional way, rather than to write Java/Python with a new syntax. This is expected to be difficult – you are learning to think in a completely new way!