CTM: Exercise 3-10

Posted by Urban Hafner Thu, 15 Sep 2005 18:55:59 GMT

The problem

Checking if something is a list. Section 3.4.3 defines a function LengthL that calculates the number of elements in a nested list. To see whether X is a list or not, LengthL uses the function Leaf defined this way:

fun {Leaf X} case X of _|_ then false else true end end

What happens if we replace this by the following definition?:

fun {Leaf X} X\=(_|_) end

What goes wrong if we use this version of Leaf?

My solution

What happens is that when you call the second definition of Leaf with a non-nil value the computation suspends. I’m also not entirely sure on this one. But what probably happens is this. The two _ create two new unbound variables in the store. This then means that the disentailment check can’t decide and blocks.

Tags , , , , ,

Comments are disabled