EECS 662

Programming Languages

Index
Blog

Using error

I’ll hit this in class today, but posting here in case anyone misses lecture.

In the first problem on Project 0 I ask you to use the Haskell error function to throw an error in your interpreter. This is not hard. In fact, it is so not hard that I forgot to cover it in class for those who have not seen it.

When you want to halt a Haskell program in an error state, you can always use:

error "nifty error message"

This causes your program to terminate completely and generates the error message specified. You can use this where you might otherwise use Nothing in a monadic interpreter. However, your program terminates immediately and returns no value. This is quite different from Nothing which is a value that indicates the computation was not successful. Very different things, but useful in the same situation.