# Haskell For Kids! Introduction

In a couple weeks, I’ll be posting a blog entry once a week called “Haskell for Kids”. This is an introduction to what that’s all about.

### What Is It, and Why?

I have the excellent chance this school year to teach Haskell to a group of children aged 12 to 13 years old! I’m very excited about it. I’m teaching the class as part of the Little School on Vermijo, which is a neighborhood school taught by my neighbor, Sue. I love this concept: the school meets in her living room, it’s a very small class, and a lot of people in the neighborhood are pitching in with subjects here and there. Last year, I taught a once-a-week mathematics class, which was really great. This year, I’m trying programming for two hours per week.

### Haskell? Really?

Yes, I picked Haskell for a programming language. That will be controversial, of course, but I think I have good reasons.

- It’s something I’m excited about! I think that’s bigger than a bunch of technical details: it’s important for everyone to teach what you’re excited about, and pass that excitement to others.
- Ben Lippmeier’s Gloss library is an excellent educational tool. It’s a library for building graphics-related programs with a high-level, composable, and semantically meaningful API.
- I think Haskell is the best environment to learn and practice abstract patterns of thinking that will be useful in mathematics, logic, and a clear understanding of the world. You see, I don’t care whether anyone comes out of this class headed for a computer programming career. If they’ve got their heart set on being a poet, I hope to have contributed something valuable to their lives, too.

The objections I’ve heard when I’ve discussed the plan with others come down to Haskell being “hard”. I think that’s an oversimplification. If you look at the reasons Haskell is considered “hard”, a lot of it comes down to: (a) it’s different from other languages that people are used to, and (b) people are doing hard things with it. Neither objection applies in this class.

That’s not to say that Haskell ought to be everyone’s choice. If you’re looking at teaching programming to children, I think the most important thing is to avoid *incidental* complexity. Any language that lets you get right to talking about what you want to do is suitable. If I weren’t doing this in Haskell, I’d be choosing Python. But excitement matters, so Haskell it is.

### What’s Blogs Got To Do With It?

The actual class will be happening two mornings a week on Tuesday and Wednesday. In the process of planning, though, I ran into the inevitable problem that there aren’t really any textbooks for teaching Haskell programming to 12 year olds! So in lieu of a textbook, here’s my plan:

- Of course, I’ve done some preparation: made an outline of several dozen topics, and mapped out the dependencies between them, and ideas for exercises in Gloss that might accompany each one. I don’t intend to share this, though, because I want to avoid locking in to a pace or syllabus before we even get started.
- Each week, directly
*after*that week’s two classes, I’ll write up my notes of what we talked about, and publish them in that weeks’ Haskell for Kids blog entry as a review. - My students will be assigned to come comment with specific questions they have, or with comments on things they found interesting, additional ideas that came to mind, or what they were able to do with their programs that seemed cool.

I hope to accomplish a couple things with that structure.

The first, and least interesting, is to have a written source for anyone in the class that wants to go back and review topics from the past. To be honest, I hope this isn’t very common. If I’ve got people needing to constantly go back and copy code from past lessons, then I think that’s a pretty good indication I’m going too fast! That said, though, it will be nice to have the notes available, especially for students who are absent or just find it useful to go back and read it again.

The second, and more important, thing I hope to accomplish is to connect students in this class with a larger community. Anyone else reading this blog, whether you’re learning Haskell or a part of the community already, is encouraged to jump in the conversation and participate. I know I’ve talked to at least three or four people, from when I originally asked around for experiences with this through now, who wanted to be kept up to date on how it goes, or even follow along. This is your chance!

### A Preview of the Class

I’m organizing the class around the structure of Ben’s Gloss library, which happens to be related to a nice progression of programming ideas as well! So the best way to explain the structure will be to mention the four entry points in Gloss:

displayInWindow

This is the simplest of the four Gloss entry points: you give it a picture, and it displays the picture in a window. We’ll use it to look at basic types of data (numbers, boolean values, etc.), structured types (for example, lists and tuples), expressions, precedence and order of operations, variables, and list comprehensions.

animateInWindow

This Gloss entry point displays an animation, represented as a function that maps the current time to a picture. We’ll use it to talk about defining functions, conditionals, pattern matching, and type declarations.

simulateInWindow

The third Gloss entry point runs a simulation, which differs from an animation in that it maintains a state. We will use it to discuss defining and operating on our own data types.

gameInWindow

The fourth and final Gloss entry point runs a simulation with user input, which is suggestively called a game. We’ll use this to talk about issues arising in larger-scale programs: recursion in both code and data, modular programming, simple data structures, and building complex data types. At this point, I also expect to transition even more toward providing time for practice, and encouraging everyone to create something of their own.

The exact time allocations for each part will be determined over the course of the year, so we’ll see how it goes! If you’re interested, I hope you stick around.

Your heart is the right place. Thanks for taking on this task.

We have been doing what you’re planning to do for 15 years. For 12-14 year olds, I’d use the Bootstrap curriculum, which you can find at

http://www.bootstrapworld.org/

Everything is totally functional in this world, though not in Haskell syntax. We use the teaching languages for Racket (formerly PLT Scheme) instead. From Bootstrap, it is easy to cross over into the full-fledged ProgramByDesign curriculum

http://www.ccs.neu.edu/home/matthias/HtDP2e/

It is not typed like Haskell [I could write up why we decided against types], but all of the ‘by design’ part is type-driven. We have found that because everything is functional kids really acquire skills that directly and w/o detour transfer to mathematics. At the same time, if they so wish, they can continue on a smooth path from here to full-flegded large-scale programming, including Typed Racket with first-class polymorphic functions and all.

Of course, it should also be reasonably easy to transfer our curriculum into Haskell, except that these imperative monads will obscure the mathematical clarity.

Good luck and I am anxious to find out how you will do.

— Matthias

Matthias, thanks for the comments. I’ll definitely look through the bootstrap curriculum and see what’s there that I can move over into the new setting.

It turns out that while, of course, imperative programming with the IO monad is possible, it won’t be a big part of this. Gloss is a beautifully functional graphics programming environment built on the idea of composing simple pictures together. See http://hackage.haskell.org/package/gloss for details, and in particular the Picture type from the Graphics.Gloss.Data.Picture module. Though main still has an IO type, it’s typically just a direct call to one of displayInWindow, animateInWindow, etc.

Cool, the earlier the better. My kid is taking java for his first full language course in 10th grade. My first language was BASIC at age 15. If only.

Can you say what town is this happening in?

You’re asking about the town for my class? Colorado Springs, CO.

Sounds great! I’m looking forward to the series. Maybe someday I’ll be able to teach my daughter Haskell (my wife so far has resisted ;).

Wonderful. I’ve been teaching my 8 y/o daughter Clojure, which I chose over Haskell for two reasons: dynamic types and impurity. I felt that purity, in particular, would be too onerous a hoop for us to jump through. I’m very curious to see what your course ends up looking like, as I’d be delighted to introduce her to the beauty of Haskell, too.

This is very exciting! Thanks for sharing!

The whole school meets in your neighbour’s sitting room? How many kids go to the school? How many are in your class? I thought our son’s school was small (150).

Best wishes

Ivan

Yep! There is only one class. Last year it was 6 students. It’s limited to 12, but the exact numbers vary and I don’t know exactly how many there will be this year. Obviously, no typical school! Sue has decided her job title is “founder, lead teacher, principal, superintendent, custodian, secretary, and lunch lady”. Several of the rest of us come in for specific subjects.

Last year for the second half of the year, I taught a math class… while all the students had a core math curriculum that they worked on daily, I got to do the fun stuff once a week: playing with the Towers of Hanoi puzzle, trying to tile surfaces with different collections of shapes, making up dice games for fake money and calculating the probabilities of winning. We even spent a couple weeks working through the proofs of the six-color theorem and the five-color theorem. We read life stories of Galois, Cantor, Abel, Godel, and more. (Ever noticed how many of them died early or in odd ways? I have a thank-you email from one of last year’s students that ends “I think you’re a great mathematician, but I hope you don’t die a horrible death.”)

Basically, it’s just plain amazing. I’m grinning just thinking about it, and really looking forward to doing it again.

I’m 39 years old, I tried understand Haskell and I failed. I hope to learn something from your kids :D

Great! Thanks a lot for learning Haskell to kids. My boys (8 and 10) start to ask me about programming. I started with Scratch (http://scratch.mit.edu/), but find it very limiting. Though I am still quite new to Haskell, I will give a try with Gloss and will keep reading your posts. I hope you will publish some examples that we will be able to try out.

I hope you post some of your curriculum. I bet us “older folk” could learn a thing or two, and would love to keep the info for when my turn comes to teach the next gen :)

I hope the class turns out well. I’m curious what development environment you’ll be using, will you be teaching them the command line or is there some IDE I’m not aware of. I just started to write an introductory programming book yesterday (you commented on my forrst post about teaching functional programming as an introductory course) and I chose Scheme over Haskell because of the DrRacket IDE, which although i use TextMate and the command line for everything, I feel the IDE is best for teaching. Is there a good IDE for haskell you would recommend?

Come to think of it, there’s really a gap in the market. As far as I know, the only good book for learning haskell is “learn you a haskell”, which although I think is great, is not usable as an introduction to programming. That’s why I’d really rather write the book on Haskell than Scheme.

It’s a great project that could be a good starting point for programming instead of use OOP. i hope this kids enjoy that subject becouse Haskell is not too dificult and in some ways turns funny. As andrusi, i’m curious how would be this projet done, if the kids enjoy programing or not.

Haskell For Kids! Introdսctiօn