3 ms·
>The Python code has the added advantage of actually being correct, assuming that the intended behaviour really is to add up the total of all entered numbers ov
by asdasf 13y ago
>The Python code has the added advantage of actually being correct, assuming that the intended behaviour really is to add up the total of all entered numbers over time as the output suggests.
What output? I don't understand why you wrote python code that does something different than the haskell example does, and then decided that makes the haskell code wrong.
- Chris_Newton 13y agoI think if you’ve got an example of an open-ended read loop, and it collects numbers, and you’re printing something that says “Total:”, it’s reasonable to ask whether the intent was to print the total of the numbers collected by the loop so far. That this side discussion has happened almost makes my point for me. If the Haskell code had described what the mutable state actually was (the total to date or the previous entered value) rather than getting hung up on the fact that it was mutable state at all (even as written, the term “state” appears five times in this trivial algorithm) then we wouldn’t be having this conversation.
- asdasf 13y ago>it’s reasonable to ask whether the intent was to print the total of the numbers collected by the loop so far. Yes, it is reasonable to ask that. But you just said it was incorrect, you didn't ask that. >That this side discussion has happened almost makes my point for me I don't see how. Your point appears to be "I can write shorter python". You can write shorter haskell to do that too, the point was to demonstrate the State monad, not to be concise.
- dllthomas 13y agoIf the code isn't incorrect, the label printed is. It is not computing the total.