# Mini-Projects that can be covered in an 1 hour Haskell tutorial

I am supposed to be holding a tutorial session in an Undergraduate Haskell Course, which is also supposed to be a first course in programming for a few of the students. Ideally, the tutorial should be interesting, interactive and inviting problem solving skills.

My audience is a group of Undergraduate students, a large number of which are mathematically oriented and a few graduate students, majoring in Computer Science. For the undergraduate students, it can be assumed that quite a few of them are new to programming or CS in general. And functional programming is new to almost everyone. This tutorial is part of a course they are all attending - the aim of which is to introduce programming.

I am wondering what sort of things I could cover in such a tutorial. Some ideas I had are these:

• A sudoku solver
• A Brain**** Interpretter
• An Arithmetic Expression Parser and Interpretter
• Discussing a data structure which the students have not seen before - like binomial heaps, or red black trees

What other things could I try? Functional Programming specific applications are especially welcome.

• Go with the sudoku solver man. Easy to explain and easy to implement as well. and welcome to the site because, you know, you are here :P
– Jay
Sep 13 '17 at 4:25
• Well, idk if I have a project idea for you, but based on your updated description, I think you can immediately reject your last three ideas. If most of your audience is new to programming, I don't think they'll either appreciate, care, or have the background to understand those three mini-projects. I would also recommend not approaching this from the perspective of "how can I introduce these students to Haskell/functional programming" -- I'd approach it from the perspective of "how can I introduce these students to programming" and ignore the people who are already familiar with CS. Sep 13 '17 at 5:44
• wait, a f word is allowed in a question?
– Jay
Sep 13 '17 at 11:44
• Welcome to Computer Science Educators! Not an answer, but all of those projects strike me as very ambitious for a novice programmer, though if they're not programming it (it's merely a demonstration), then have at it.
– Ben I.
Sep 13 '17 at 11:53
• If you can't tackle the problems in 10 minutes yourself, don't expect beginners to do so in 1 hour. Sep 14 '17 at 14:48

# The ideas in your question are far too difficult, for a one hour introduction.

Yesterday I had a look at Haskell and learnt some. I have over 30 years programming experience (20 years professional). Have experience with functional programming. Yet it took me several hours, and did not get far enough to be able to do your suggestions.

# Mathematics

You say that your students have a maths background.

Take advantage of this. Choose some math problems. That Haskell is ideally suited to solve. And explain why you are doing this.

Ensure that you have more than you think you will need, as some students will be much faster than you expect, but don't expect to use them all.

There are some good ideas here https://stackoverflow.com/a/15110828/537980 also some of the other answers, to the same question: sort, search, interpreter (this one may take too long), factorial.

Don't do problems that are more difficult in a functional language than in a procedural one (Reversing a list, using procedural techniques, in $$O(n)$$, is easy. If by using functional they will probably get a $$O(n^2)$$ solution, and $$O(n)$$ is hard, then you are teaching a disadvantage on day one.)

Fibonacci is, I think $$O(2^n)$$, for simple recursive implementations.

fib 0 = 0
fib 1 = 1
fib n = fib (n-1) + fib (n-2)


I did it in $$O(n)$$ once, that was the day I learnt a lot about caching. It was hard, it took me a whole day.

• Any suggestions on what math problems I could talk about? Sep 15 '17 at 2:40
• Added examples, counter example, and a link. Sep 15 '17 at 8:04
• On the other hand, if it's a demo rather than an exercise, a functional $O(n)$ Fibonacci can be just fibhelper 0 a _ = a; fibhelper n a b = fib (n-1) b (a+b); fib n = fibhelper n 0 1. (Although I suspect an idiomatic Haskell version would use a lazy infinite sequence and take the nth element). Sep 15 '17 at 10:31
• @PeterTaylor very good. However you made an error: you call you called fib with 3 arguments. I changed it to fibhelper, tested it, thought it through and it worked. Fixed code fibhelper 0 a _ = a; fibhelper n a b = fibhelper (n-1) b (a+b); fib n = fibhelper n 0 1 Sep 15 '17 at 12:01
• They are not at all too difficult if you are being guided and can evaluate code during the tutorial to follow along. Parsers in Haskell are amazingly elegant, but also have an air of practicality that can help keep novices interested. A really simple arithmetic expression parser and evaluator is just one line: expr = "(" *> expr <**> ("+" $> (+) <|> "*"$> (*)) <*> expr <* ")" <|> decimal. This also gives the opportunities to talk about some very useful Haskell operators and the importance of the little details in formal grammar definitions. 1 hour should be enough to cover 1 line of code. Feb 20 '19 at 16:47