Instantiation and Strictness

These are lecture notes from my Computer Science course. For learning about functional programming, in particular Haskell, I recommend Programming in Haskell.

Be careful when doing program transformation with regards to strictness. The problem is sometimes your function just passes a variable straight through as input. When this happens, ‘undefined’ can also be passed through just fine. But if you perform program transformation, which involves explicitly defining instances of a function, by proxy (by performing pattern matching in the program) you introduce name_of_function 'undefined' = 'undefined', which may not be what your original program did.

So, before you perform any instantiation make sure that the function is strict. If it isn’t, instantiation is unsafe. The example used in the lecture was the ‘interoman’ function.

How do you solve this?

Unfold as far as you can go before breaking instantiation.

Something else, that I missed.

This entry was posted in fun, lecture. Bookmark the permalink.