Teaching functional programming to engineers

I teach at an engineering school where we have two different tracts of students. Some students are full-time students who attend classes during the fall and spring. Other students are called “apprentis”, they have contracts each with a different company, and they work two weeks at the company and attend classes for two weeks, in cycles through the fall and spring. In general the full-time students have a more theoretical curriculum including a course in Functional Programming. However, the apprentis, haven’t taken the functional programming course.

This year I suggested to the school that I teach an “Application of Functional Programming” course to the apprentis, and that I use Scala as the programming language. They accepted my proposal! Yipee!!!

These are students who have experience in programming, but different students have used different languages and different domains depending on which companies they are working with.

Imposed are 4 three hour lectures–I have no choice about the time allocation. So I have tried to present 8 units, 2 per class session.

However, I had to dedicate far more time getting the environment working that I hoped.
For most students (50 of 70 students) it worked correctly, out-of-the-box. But for about 20 students, it failed for various reasons, and we had to debug it over time.

The environment is this. I give them a git repository which include the lecture notes, the code developed in class, templates for homework exercises, and test suites. The students have to install IntelliJ and the Scala plugin. I plan to eventually generalise this to also work with VScode, but that work is still on my TODO list.

The homework templates contain incomplete code. The students have to replace the occurrences of ??? with real code which passes the tests.

There have been several challenges to make this work. Perhaps I’ve solved the problem wrong, but I finally got a flow that works.

One frustrating problem is that the Scala language does not fully support ???. Some occurrences of ??? cause the code to fail to compile. Why is this a problem? Because if homework exercise 2 has such an issue, then the students cannot complete homework exercise 1.

To resolve this, I put the homework exercises in a templates/ directory. For each exercise the, student must copy the template file into a real directory to complete the homework.

This causes another problem, the test suites fail if they mention functions which are only in the uncompiled templates directory. This means students cannot run ANY of the tests unless ALL of the test suites compile. Therefore the fix is to also put the tests in an uncompiled templates directory.

If anyone cares to take a look at my repository, it is publicly available.

Hey @jimka,
I have had a quick look at the repo it looks like it contains nice exercises!
Could you please expand a little bit on the situations where an exercise prevents another, unrelated, exercise to not compile? The only situation I can think of is when there is code following a ??? , then the compiler would emit a reachability warning, which could be promoted to an error depending on your compiler options. Another thing I have in mind is if something involving a ??? is eagerly evaluated, then the program execution will stop eagerly…

Hi Julien, I don’t know the complete list of issues. But here, I have prepared a repository which demonstrates many of the issues.

If you try to build the project, you see lots of compilation errors. I’d rather these NOT be compiler errors, but run-time errors, as intended (in my undemanding and opinion) by the ??? syntax.

Here is list of some of the errors

Error 1

value toVector is not a member of Nothing
                       Vector(gender_raw, name_raw, year_raw, count_raw ) = ???.toVector

Error 2. This one seems to be really an error in the compiler. It should be able to infer the type Nothing here, in my opinion. The type of acc is Nothing and the type of year is Nothing.

missing parameter type
    (yearMin to yearMax).foldLeft(???)((acc,year) => ???)

Error 3. This seems like an error n the desugarer, or rather the compiler should understand that Nothing has all method regardless of name.

value map is not a member of Nothing
    val it = for {line <- ??? // HINT: fp.getLines().??? // drop the line sexe;preusuel;annais;nombre

Error 4

value map is not a member of Nothing
                  n <- ???

Alright, I think most of the errors you see come from the fact that the type Nothing is inferred at a couple of places.

The only solution I know to fix this issue is to use type ascriptions to fix those types to something else than Nothing.


val columns: Array[String] = ???
val Vector(gender_raw, name_raw, year_raw, count_raw ) = columns.toVector
(yearMin to yearMax).foldLeft[Int](???)((acc, year) => ???)


I know this is not perfect but that’s the best I can think of.