Changes to Typeable

wren ng thornton wren at
Tue Oct 9 22:46:10 CEST 2012

On 10/8/12 7:27 AM, Simon Marlow wrote:
> Code size?  It might only be a small effect for most code, but we
> occasionally see large files of automatically-generated data declarations.
> Also I rather like it that making a new data type is so cheap in terms
> of code size.  A single module containing "data T = A | B":
> $ size foo.o
>     text    data     bss     dec     hex filename
>       91      32       0     123      7b foo.o
> If I add "deriving Typeable":
>     text    data     bss     dec     hex filename
>      587     312       0     899     383 foo.o
> 7x larger!

Just in terms of optimization: because they're so lightweight, I've been 
a big fan of making new data types whenever the slightest need arises--- 
as opposed to the common practice in other languages of using some 
"close enough" data type to avoid making a new one. For example, with 
accumulator-based functions I often codify the accumulator with a data 
type to help clarify the code and ensure the appropriate strictness. The 
majority of these throw-away data types are ones which are only used 
internally and will never leave the module. It'd be nice, therefore, to 
only autogenerate Typeable instances for data types which actually have 
a chance of needing them--- i.e., are exported (or use Typeable internally).

Live well,

More information about the Libraries mailing list