News for hackers. Stuff that matters.
Re:Ask HN: How would you do this in Haskell? by stonemetal on Wednesday April 22, 2015 @01:07PM (#9421859)
There is a problem with your premise. Why do you need to log in the middle of that function? In a procedural language you need to log right then to make sure state hasn't changed on you. In Haskell you could do it before or after the function and not be able to tell the difference because state can't change on you.
Re:Ask HN: How would you do this in Haskell? by AnimalMuppet on Wednesday April 22, 2015 @01:57PM (#9422209)
No, it's not a matter of the state changing. The premise is that, at each step of the calculation, a function does some computation and returns a result. At the point where the logging decision is being made, the decision is based on data available within the function, but not being returned by the function - only a derived value is returned.

Now, perhaps you could argue that the right way to do the problem (without the logging) in Haskell is to not have functions like that - to break up that function so that the data that, in my version, is only available within the function is instead explicitly returned by some smaller function.

But if you don't argue that, then you're left with the stated problem: What's the right way of getting logging out of the middle of a function in Haskell?

Re:Ask HN: How would you do this in Haskell? by chris_j on Wednesday April 22, 2015 @01:57PM (#9422211)
What if you want to see an intermediate value part way through a complex calculation?