Changes that are desirable for correctness, safety, performance, or cleanup, split into breaking API changes and breaking wire-format changes.
Binary (Set.Set a) and Binary (Map.Map k e) currently have no Ord
constraint on their element/key type:
instance (Binary a) => Binary (Set.Set a)
instance (Binary k, Binary e) => Binary (Map.Map k e)Because get uses Set.fromDistinctAscList / Map.fromDistinctAscList
without verifying that decoded keys are strictly ascending, malformed or
untrusted input can silently construct a Set or Map with corrupted BST
invariants.
For the next breaking release:
- Add
Ord atoinstance (Ord a, Binary a) => Binary (Set.Set a)andOrd ktoinstance (Ord k, Binary k, Binary e) => Binary (Map.Map k e). - Validate that decoded keys are strictly ascending in a single pass while
decoding (matching
Binary IntSetandBinary (IntMap e)), failing cleanly on duplicate or out-of-order keys.
Consider removing long-deprecated functions in a major release:
Data.Binary.Get.runGetStateData.Binary.Get.getBytesData.Binary.Get.remaining
Set, Seq, Array, and UArray currently encode elements with a strict
Builder fold (foldr (\x acc -> let b = execPut (put x) in b seq (b <> acc))),
which still allocates per-element BuildStep closures (~180 B/element for
UArray Int Int, vs ~11 B/element for [Int] using Prim.primMapListFixed).
They cannot reuse putList directly because putList also writes a length
prefix. Adding a lengthless putElems :: [a] -> Put (or putElemsBuilder)
method to Binary in a future release would let containers reuse
Prim.primMapListFixed for primitive element types.
Binary Double (and Binary Float) currently encode values using
decodeFloat / encodeFloat (a (Integer, Int) mantissa/exponent pair),
which:
- Uses a non-standard, bloated wire format (13–25 bytes per
Doubleinstead of 8 bytes, and 13 bytes perFloatinstead of 4 bytes). - Does not round-trip
NaN(or preserve-0.0/ NaN payloads). - Is significantly slower to encode and decode than raw IEEE-754 words.
For the next wire-format-breaking release (see haskell/binary#69):
- Switch
Binary Doubleto IEEE-754 big-endian (putDoublebe/getDoublebe, withPrim.primMapListFixed Prim.doubleBEforputList). - Switch
Binary Floatto IEEE-754 big-endian (putFloatbe/getFloatbe, withPrim.primMapListFixed Prim.floatBEforputList).