
On 8 March 2010 12:06, Magnus Therning
What am I missing?
Hi Magnus I was restating what Jonas mentioned but didn't elaborate - that Joe's original program had a type error. The solutions posted did two things: 1. Rewrite Joe's original (algebraic) data type to encode it with products (aka pair - (,) ) and sums (Either) - this allowed some of the pattern matching to be factored, reducing the number of cases in the function test from 4 to 2 2. Correct the answer type to use a proper sum (Either Int String), where previously some of declarations of test returned Int others String (and so wouldn't type check). Strictly speaking your program wasn't "equivalent" to the original because it did step 2 and would actually work! Best wishes Stephen