External Publication
Visit Post

Changing the `Binary` instance for `Double` and `Float`

Haskell Community [Unofficial] March 7, 2026
Source

I use cereal for saving and restoring state. I switched from binary many years ago due to something I forget, I vaguely recall it was more strict in some important way. Actually it turns out at some point I also stopped using its Serialize class and wrote my own, which I think was due to Float serialization messing up -0, so it’s actually somewhat related to the topic. But also it’s necessary to retain control over backward compatibility, since as is being discussed, the libraries are free to change the format if they’re not implementing a standard.

So in my case, I think it’s fine to fix Binary Float, it would have saved me from a surprise, though I would also document that if you need a stable format, don’t use the library’s typeclass but write your own. Also, it’s fast enough for me, I don’t really have a need for high performance. I’m just curious about what is efficient and what is not. Also I recall a rationale behind wanting better performance for binary was that ghc used it, and of course anything that can speed up compiles is welcome.

Is there a relevant distinction between deserialization and parsing? I think of what I’m doing as the former, there aren’t any branches except some version checks, whereas what I think of a parser has a lot of “or” operations and hence might have things like backtracking. Maybe the distinction is too fuzzy to be useful though.

Discussion in the ATmosphere

Loading comments...