4 ms·
I still don't understand why you even raised a reddit thread -- "Go with Data.Binary.IEEE754 and see if there's any reason not to like it -- it just works"
by dons 13y ago
I still don't understand why you even raised a reddit thread -- "Go with Data.Binary.IEEE754 and see if there's any reason not to like it -- it just works"
- zvrba 13y agoIs "genuine intellectual curiosity" a good enough answer? I tried to figure out by myself how to reinterpret_cast a ByteString to something else (Float/Double in my case). I used ByteString because it was recommended by #haskell for binary IO. I failed in my endeavor because the key function, which returns the pointer underlying ByteString, is in the hidden Internal subpackage. So I asked on reddit.
- dons 13y agoThe internal module isn't actually hidden. toForeignPtr should get you there: http://hackage.haskell.org/packages/archive/bytestring/0.9.1.4/doc/html/Data-ByteString-Internal.html#v%3AtoForeignPtr http://hackage.haskell.org/packages/archive/bytestring/0.9.1...
- zvrba 13y agoThis is a chicken-and-egg problem. Had I known about the existence of toForeignPtr [the link to Internal module doesn't even appear in the locally installed library docs], I would not have had started the reddit thread. Again, how was I supposed to know about the existence of Internal submodule and toForeignPtr function?
- dons 13y agoI suppose it should have gone like this: * You need to unmarshal hardware floats * You visit Hackage, and use the IEEE754 package. http://hackage.haskell.org/package/data-binary-ieee754 http://hackage.haskell.org/package/data-binary-ieee754 If that is fast enough, you stop. You are done. * IEEE754 is too slow for some reason, so you decide to do your own unsafeCoerce of bytestring * You look at the source for IEE754 and decide to marshal memory yourself: http://hackage.haskell.org/packages/archive/data-binary-ieee754/0.4.4/doc/html/src/Data-Binary-IEEE754.html#wordToDouble http://hackage.haskell.org/packages/archive/data-binary-ieee... * You read the bytestring package docs: http://hackage.haskell.org/packages/archive/bytestring/0.9.1.4/doc/html/Data-ByteString-Internal.html http://hackage.haskell.org/packages/archive/bytestring/0.9.1... and pay attention to the "unsafe" functions that cast raw pointers. * That lets you re-implement the IEEE754 package your own way The mistake here was not using the highly-optimized existing library - http://hackage.haskell.org/packages/archive/data-binary-ieee754/0.4.4/doc/html/src/Data-Binary-IEEE754.html#wordToDouble http://hackage.haskell.org/packages/archive/data-binary-ieee... - which already does the correct thing. You jumped straight to "have to roll my own low level binary parsing" and then started a reddit thread instead. None of that was necessary.
- zvrba 13y ago> "have to roll my own low level binary parsing" But that was the whole point from the beginning! Find out how can I do it myself. > You read the bytestring package docs: I repeat: the Internal module isn't listed in the locally installed documentation, and the link on Hackage is broken. Do I really need to produce for you the two top-level links where I was looking for the documentation of Internal?