cs3110 / textbook

The CS 3110 Textbook, "OCaml Programming: Correct + Efficient + Beautiful"
Other
720 stars 132 forks source link

fix Memoized.party #78

Closed v1nh1shungry closed 2 years ago

v1nh1shungry commented 2 years ago

fix https://github.com/cs3110/textbook/issues/37

Just think about the simplest situation, that is, there is only one node in the org chart. For example,

let t = Memoized.(Node (100, "Vincent", Empty, Empty, ref None))

Then in party t, obviously party_in t wins. Let's dive into party_in t. Obviously party_out l and party_out r both return (0, []), so party_in t will return (v + 0 + 0, name :: [] @ []), that is, (100, ["Vincent"]). Go back to party t

if infun > outfun then (v + infun, name :: innames)
else (outfun, outnames)

it will return (200, ["Vincent", "Vincent"]), which is obviously wrong.