News for hackers. Stuff that matters.
Re:Why I Love Haskell: An Example by azylman on Wednesday April 08, 2015 @04:01AM (#9339278)
This can be done very easily using an unbounded io.Reader instead of channels or iterators.

Here's a slightly modified version of bluefox's code where the prf function returns an unbounded io.Reader: https://play.golang.org/p/ZAj8q4eXEi

And here's a version that's modified a bit more, but still essentially the same, to trade LOC for matching the spec very cleanly: https://play.golang.org/p/Rpy0yIwVN1

Re:Why I Love Haskell: An Example by belovedeagle on Wednesday April 08, 2015 @10:02PM (#9345429)
Just to be clear, a Pipe counts as a channel for me; like I said, it requires a goroutine. Don't get me wrong, this is definitely the "right" go implementation, and what GHC does internally with thunks is way worse than goroutines.

The point is it no longer looks so superior to the Haskell version, especially since there were many LOC in the haskell version just defining the Key datatype which go never does.

Re:Why I Love Haskell: An Example by ICWiener on Wednesday April 08, 2015 @04:57AM (#9339451)
I don't see any kind of error handling, but if I understand correctly, in some cases in Go it is not necessary to check for errors directly (an errorneous output stream would do-nothing on write, for example). Do you think your versions are fault-tolerant or is there anything you should add to gracefully handle errors?
Re:Why I Love Haskell: An Example by azylman on Wednesday April 08, 2015 @02:14PM (#9342689)
A Hash's Write method can't return an errors.

Writing and Reading to a pipe only errors if the pipe has been closed. We return an io.Reader, instead of an io.ReadCloser, so consumers can't close the Read side. Internally, the Write side is never closed either. So, in practice, Reading and Writing also won't ever error.