Assume I created a type as follows:
data RequestAck =
RequestAck { ackOK :: Word32, ackMsgCode :: Word32 }
I can see that it is 2 * 4 bytes big and make that a constant somewhere.
The only problems is that once I add a field to the type, I'd have to remember to update my constant.
Is there a function out there that will provide me with the size of a given type e.g., t -> Int
?
The function that comes close to what I want is
gsize :: Data a => a -> Int
inside the Data.Generics.Schemes module, but I don't want to have to make my type an instance of Data
.
Is there a more generic solution out there?
To be sure, I'm looking for a function that operates on the static type, e.g., I don't want to pass an instance, but the type itself.