sassa_nf ([personal profile] sassa_nf) wrote 2023-12-31 11:57 am (UTC)

That's right, it is not. It is a complete rebuild of the solution, having revisited the 10+ yr old exercises.

Yet, you can probably see why that first solution is a sort of hylomorphism. It solves problems for specific types of (p -> f p) - such that they produce a value no bigger than the input tree, and such that use the value in the node, not the whole subtree. Also, the function is plugged in the wrong place, but it still has to know whether the seed value is for left or right, hence the Bool argument.

Taking these things into account, I tried to incorporate both trees into the type of the seed explicitly. Consequently, the output of the function becomes a tuple, or rather a Maybe tuple, since it should have a way to stop the recursion, which is represented by Tr a x here. The right design falls out of these considerations.

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting