`putEnum` in `GHC.StgToJS.Object` could be simpler and more general (and more correct)
It seems there is some effort in GHC.StgToJS.Object to save some space by restricting putEnum to work with Word16.
However, the binary instance for all word types is exactly the same and uses a variable length encoding.
Either
- Replace
Word16withFixedLengthEncoding Word16if you actually want to serialise precisley two bytes (always). - Use something bigger than Word16 and remove the check that
n > 65535
It also seems that this check that n > 65535 is always going to fail anyway as 65535 is the maxBound of Word16 so values will already have been wrapped by the time the comparison happens.